I would take to take the mean of the columns by a certain break
of the rows. For instance:
set.seed(0)
dt = data.frame(cbind(rnorm(10, 0, 1), rnorm(10, 0, 2), rnorm(10, 0, 3)))
breaks = c(0,1,2,4,8,Inf)
The only solution I can think of is manually plug in row index then use colMeans
or use loop
, which is painful since I have a much longer break
rule. My expected results are as following:
re = rbind(colMeans(dt[1, ]), colMeans(dt[2, ]), colMeans(dt[3:4, ]),
colMeans(dt[5:8, ]), colMeans(dt[9:10, ]))
Any advice (or direct to a duplicated answer) is appreciated!