I am trying to apply multiple functions to multiple columns of a data.table
. Example:
DT <- data.table("a"=1:5,
"b"=2:6,
"c"=3:7)
Let's say I want to get the mean and the median of columns a
and b
.
This works:
stats <- DT[,.(mean_a=mean(a),
median_a=median(a),
mean_b=mean(b),
median_b=median(b))]
But it is way too repetitive. Is there a nice way to achieve a similar result using .SDcols
and lapply
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…