Description Usage Arguments Details Examples
Sequentially aggregate columns in a data.table, varying the function and 'by' values
1 |
X |
a data.table |
val |
character vector indicating columns in X that should be sequuentially aggregated |
FUN |
a list of functions |
by |
a list of character vectors; should be of same length as FUN |
... |
arguments to be passed to each element of |
The lengths of FUN
and by
should be of the same length, but the length of val
is independent.
Useful when a summary statistic needs to be computed sequentially (possibly taking the mean over some dimensions before computing the standard deviation, e.g.)
1 2 3 4 5 6 7 8 9 10 | neus_dat <- data_all[reg=="neus"&year==2010]
a1 <- c("K","stratum")
a2 <- c("stratum")
a3 <- c("")
a_list <- list(a1, a2, a3)
f_list <- list(mean, mean, sd)
neus_dat[,sd(btemp,na.rm=TRUE)] # naive
seqAgg(neus_dat, val="btemp", FUN=f_list, by=a_list, na.rm=TRUE) # sequential
seqAgg(neus_dat, val=c("btemp","depth"), FUN=f_list, by=a_list, na.rm=TRUE) # 2 columns
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.