我有这个数据:
thedat <- structure(list(id = c(" w12", " w12", " w12",
" w11", " w3", " w3", " w12",
" w45", " w24", " w24", " w24", " w08",
" w3", " w3", " w11"), time = structure(c(1559329080,
1559363580, 1559416140, 1559329380, 1559278020, 1559413920, 1559285100,
1559322660, 1559417460, 1559450220, 1559500980, 1559500980, 1559278020,
1559413920, 1559276700), class = c("POSIXct", "POSIXt"), tzone = ""),
x = c(28.03333, 18.45, 3.85, 27.95, 42.216667, 4.466667,
64.25, 53.81667, 27.483333, 18.383333, 4.283333, 4.28333336,
66.21667, 28.46667, 66.58333)), .Names = c("id", "time",
"x"), class = "data.frame", row.names = c(NA, -15L))
对于每个id
我想获得x
随着时间推移的累积总和。所以id = w11
我会得到:
w11, 2019-05-31 05:25:00, 66.58333,
w11, 2019-05-31 20:03:00, 94.48333
我试过了
ddply(thedat, .(id), summarise,
time = unique(time),
answer = cumsum(x))
但这并没有让我得到我想要的。任何帮助表示赞赏。