I'm having a lot of trouble trying to figure out how to use the aggregate function in R and I'd appreciate some guidance. About the only way I could get aggregate to work was by following the syntax given here.
Given the data
data <- data.frame(alpha = c(1,1,1,1,2,2,2,2),
beta = c(1,1,2,2,3,3,4,4),
gamma = c(.1,.2,.3,.2,.4,.1,.3,.5))
I would like to aggregate by the columns 'alpha'
and 'beta'
. If I was just aggregating by 'alpha'
, for example, I could just do:
aggregate(x = data[ , colnames(data) != "alpha"],
by = list(data$alpha),
FUN = sum)
Trying
aggregate(x = data[ , colnames(data) != "alpha" | colnames(data) != "beta"],
by = list(data$alpha, data$beta),
FUN = sum)
didn't work. Could someone help me find the correct syntax?
Thanks!