I would like to aggregate over multiple LHS variables in R, with the outcome being distinct columns for each aggregation.
df <- data.frame(time = rep(seq(1,2,1),2),
v1 = seq(2,8,2),
v2 = seq(2,16,4),
f = c("a","b","c","d"))
df$f <- as.character(df$f)
aggregate(df$v1 + df$v2 ~ df$time, FUN=sum)
EDIT: Previous answers have suggested
aggregate(. ~ time, df, sum)
Which works as along as there are only numeric variables that are being aggregated. I have updated the code to reflect a situation in which a character type is present. I am working with a large data frame that has character variables. It is obviously possible to first extract the numeric variables from the data frame, but is there a way to do this directly? Thanks.