I want to sum up numbers by blocks:
Here is a sample data
data=matrix(c(0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,1.2,2.3,1.3,1.5,2.5,2.1,2.3,1.2),
ncol=3,dimnames=list(c(),c("low","high","time")))
low high time
[1,] 0 1 1.2
[2,] 0 1 2.3
[3,] 0 1 1.3
[4,] 1 0 1.5
[5,] 1 0 2.5
[6,] 0 1 2.1
[7,] 1 0 2.3
[8,] 1 0 1.2
I want to get
n sum
[1,] 3 4.8
[2,] 2 4
[3,] 1 2.1
[4,] 2 3.5
without using any package. How to do that with R?
Or if I can get
n/low n/high sum
[1,] 0 3 4.8
[2,] 2 0 4
[3,] 0 1 2.1
[4,] 2 0 3.5