I want to use the aggregate function in R using column index numbers to identify the data frame columns being aggregated, rather than column names.
Here's an example that works using column names:
df = data.frame(A = c("a", "a", "b", "b", "c", "c"), B = 1:3, C = 1:3, D = 1:3)
aggregate(cbind(B, C, D) ~ A, data = df, sum)
But rather than listing B, C and D within cbind, I want to instruct it to use columns 2:4.