Thanks. I tried it and it worked wonderful.
Wishing for the "DAY' to come. Life needs to be 'reset'.
--- On Wed, 7/15/09, Dimitris Rizopoulos wrote:
> From: Dimitris Rizopoulos
> Subject: Re: [R] (newbie) sum for certain number of rows
> To: "kelvin lau&q
In the zoo package, rollapply can do that.
> library(zoo)
> out <- rollapply(ts(dat), width = 3, by = 3, sum)
> out
Time Series:
Start = 3
End = 9
Frequency = 0.333
V1 V2 V3 V4 V5 V6 V7 V8
3 1 0 1 1 1 1 1 1
6 1 1 1 1 0 0 1 1
9 2 3 2 3 3 2 3 2
This gives a "ts
one way is the following:
dat <- read.table(textConnection(
"0 0 1 0 0 1 0 1
0 0 0 0 0 0 0 0
1 0 0 1 1 0 1 0
0 0 1 1 0 0 0 0
1 1 0 0 0 0 1 1
0 0 0 0 0 0 0 0
0 1 0 1 1 0 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1"
))
closeAllConnections()
k <- 3
ind <- rep(seq(1, nrow(dat)/k), each = k)
rowsum(dat, ind)
3 matches
Mail list logo