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

Hasan Diwan hasan.diwan at gmail.com
Mon Feb 13 19:56:56 CET 2012


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(1328565067, 1328565067.05, 1328565067.1,
1328565067.15, 1328565067.2, 1328565067.25), Y = c(0.0963890795246276,
0.227296347215609, 0.240972698811569, 0.221208948983498, 0.230898231782485,
0.203282153087549), X = c(0.0245045248243853, 0.0835679411703579,
0.0612613120609633, 0.058568910563872, 0.0511868450318788, 0.0557714205674231
), rownumber = 1:6), .Names = c("Time", "Y", "X", "rownumber"
), row.names = c(NA, 6L), class = "data.frame")
> speedX <- sapply(sens2[sens2$rownumber %% 2 == 0,], function(row) { cumsum(c(sens2[row+1,3], sens2[row,3]))}, simplify=TRUE)
Error in xj[i] : only 0's may be mixed with negative subscripts
Help?
-- 
Sent from my mobile device
Envoyait de mon portable



More information about the R-help mailing list