[英]Histogram in R from a frequency table with two columns?
I'm working in R and I have a table of session durations in seconds, and the count of users with a session of that length. 我在R中工作,并且有一个会话持续时间表(以秒为单位),以及具有该长度会话的用户数。 Here are some sample rows:
以下是一些示例行:
sessionDuration,users
936,5
937,3
938,2
939,4
940,12
941,2
942,4
943,1
944,3
945,4
...
I'd like to draw a histogram showing the distribution of the session durations. 我想绘制一个直方图,显示会话持续时间的分布。 For example, columns with labels for 200-400,400-600,600-800,800-1000 seconds, and then the count of users as the y-value of each column.
例如,带有标签的列持续200-400,400-600,600-800,800-1000秒,然后将用户计数作为每列的y值。
How can I do this? 我怎样才能做到这一点?
This is as far as I've got: 据我所知:
mydata <- read.csv('./session-durations.csv', header=TRUE)
hist(mydata$users,main="Distribution of users",xlab="users")
But this shows me the distribution of the value of "users" only. 但这仅显示了“用户”价值的分布。
Try this: 尝试这个:
a <- unlist(lapply(seq_along(sampledata$users),
function(x)rep(sampledata[x,1], sampledata[x,2])))
hist(a, main="Distribution of users",xlab="users")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.