Displaying 1 result from an estimated 1 matches for "xcumsum".
Did you mean:
cumsum
2024 Sep 28
1
lattice xyplot with cumsum() function inside
...ble)
library(lattice)
set.seed(123)
mydt <- data.table(date = seq.Date(as.IDate("2024-01-01"), by = 1,
length.out = 50), xgroup = "A", x = runif(50, 0, 1))
mydt <- rbindlist(list(mydt, data.table(date = mydt$date, xgroup = "B", x = runif(50, 0, 3))))
mydt[, `:=`(xcumsum = cumsum(x)), by = .(xgroup)]
mydt[, lapply(.SD, sum), by = .(xgroup), .SDcols = c("x")]
# xgroup x
# <char> <num>
#1: A 26.00455
#2: B 71.55405
#For xgroup = "B", line starts at the sum of all previous x values
including xgroup = "A&quo...