令人尴尬的简单问题...
我是R的新手,我似乎无法围绕这个原因。我有一个CSV文件,看起来像这样:
Bin,Number 1363,5 1028 ,4 1303,3 1467,1 1242,3 1415,5 .. 。容器大小为1,范围为1000-1500。我已经读取我的CSV文件,一切似乎都确定,但我只是不能产生一个简单的直方图。我试过简单地使用条形图,但数据不是数字排序,所以不会产生我需要的输出。使用这样的数据,我如何在R?中产生一个直方图?
一旦我有一个简单的直方图,我相信我可以玩因为 hist 函数会执行以下操作:
计数每个bin中的项目,您需要爆炸您已经计数的数据,例如通过使用 rep 。然后,您可以在结果向量上使用 hist 。 ,hist(rep(x = Bin,times = Number)))
Embarrassingly simple question...
I'm new to R and I can't seem to wrap my head around this for some reason. I have a CSV file which looks something like this:
Bin,Number 1363,5 1028,4 1303,3 1467,1 1242,3 1415,5 .. .The bin size is 1, with a range of 1000-1500. I have read my CSV file in, everything seems to be ok there, but I just cannot produce a simple histogram. I have tried simply using a barplot, but the data is not numerically ordered, so will not produce the output I need. Using data such as this, how can I produce a histogram in R?
Once I have a simple histogram, I'm sure I'll be able to play around with it and format it nicely.
解决方案Because the hist function does the counting of items in each bin, you need to 'explode' your 'already counted' data, for example by using rep. Then you can use hist on the resulting vector.
with(df, hist(rep(x = Bin, times = Number)))
更多推荐
使用聚合数据创建直方图
发布评论