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
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
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
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
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
5 matches
Mail list logo