【发布时间】:2017-05-31 12:14:33
【问题描述】:
我有一张这样的桌子:
Time Indicator Value
"2017-05-22 13:52:10" 1 10
"2017-05-22 13:52:12" 1 11
"2017-05-22 13:52:14" 1 9
"2017-05-22 13:52:16" 0 4
"2017-05-22 13:52:18" 0 10
"2017-05-22 13:52:20" 1 7
"2017-05-22 13:52:22" 1 9
"2017-05-22 13:52:24" 1 7
我想计算三个值:所有行的平均值,其中指标是常数。
所以我想按指标对三个 Bin 进行分组:第一个 Bin 的 Indicator=1,第二个 Bin 的 Indicator=0,第三个 Bin 的 Indicator=1。基本思想是,我想通过改变一个变量来创建箱。我该怎么做?
感谢您的帮助!
【问题讨论】:
-
rle的一个很好的用例,例如with(rle(c(1,1,1,0,0,1,1,1)), rep(seq_along(values), lengths))创建组