Re: [R] only 0s may be mixed with negative subscripts

2012-02-13 Thread Rui Barradas
Hello, > > I'm trying to get a piecewise sum of every n rows in a given column in > this data set. > Is this it? # Result as a matrix, each column a piecewise cumsum mat <- sapply(which(sens2$rownumber %% 2 == 0), function(row) cumsum(c(sens2[row-1, 3], sens2[row, 3]))) # The s

Re: [R] only 0s may be mixed with negative subscripts

2012-02-13 Thread ilai
Like this ? sum every batch of n rows? N <- 2 t(kronecker(diag(nrow(sens2)/N),rep(1,N))) %*% as.matrix(sens2) Time Y X rownumber [1,] 2657130134 0.3236854 0.1080725 3 [2,] 2657130134 0.4621816 0.1198302 7 [3,] 2657130134 0.4341804 0.106958311 Ch

Re: [R] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
On 13 February 2012 14:46, ilai wrote: > The function you posted runs without error (on these 6 lines), but > does not return anything that looks remotely like a sum, or cumsum of > anything. Can you clarify what you are trying to do? I assume by "sum > of every other row" you don't mean summing T

Re: [R] only 0s may be mixed with negative subscripts

2012-02-13 Thread ilai
The function you posted runs without error (on these 6 lines), but does not return anything that looks remotely like a sum, or cumsum of anything. Can you clarify what you are trying to do? I assume by "sum of every other row" you don't mean summing Time, X and Y for rows 1,3,5,..., ? For the sum

[R] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
I'd like to get the sum of every other row in a data.frame. When I actually set about doing this, I get the error in the subject line of this message. A sample of my data is below, followed by the function call that should give me the results I want: > dput(head(sens2)) structure(list(Time = c(132