【发布时间】:2011-04-07 22:08:57
【问题描述】:
我正在将数据分类到 bin 中并进行平均,请参阅 this solution。
我使用与上述链接完全相同的解决方案,但将我的数据固定为散点图。造成我困难的代码是:
myData.class <- cut(df$xaxis, seq(0,30,length=60), include.lowest=TRUE)
mean.yaxis <- tapply(df$yaxis, myData.class, mean)
lines(mean.yaxis ~ seq(0, 30, length=60))
对行的调用产生错误:
Error in model.frame.default(formula = mean.yaxis ~ seq(0, 30, length = 60), :
variable lengths differ (found for 'seq(0, 30, length = 60)')
调用 str(mean.yaxis) 会产生:
num [1:59(1d)] 0 0 0 0.349 4.652 ...
- attr(*, "dimnames")=List of 1
..$ : chr [1:59] "[0,0.508]" "(0.508,1.02]" "(1.02,1.53]" "(1.53,2.03]" ...
如何在调用函数 lines(...) 时访问正确的数据?
【问题讨论】:
-
如果没有您的数据,或者最好是一个小的、可重现的示例,我们的工作有点困难。
-
@Roman 我发布的链接使用了预装的地震数据集。
-
分箱连续数据通常被认为是错误的形式。我听从弗兰克哈雷尔的意见。 biostat.mc.vanderbilt.edu/wiki/Main/CatContinuous
-
@Richie 感谢您提供的信息,我实际上正在遵循 IEC61400,所以只要按照我的指示去做。但很高兴知道。
标签: r