I want to create a new dataframe with the sums of multiple variables by two grouping variables.
My data is organised as below
Management Habitat Var1 Var2 Var3
A Urban 12 6 18
A Farmland 1 9 10
A Farmland 3 10 17
B Forest 5 17 12
B Peatland 18 23 18
C Peatland 16 22 20
C Urban 16 10 21
I have the code for summing one variable across management and habitat, however I can't sum multiple variables across management and habitat to creat a new dataframe.
Code for summing one variable
newdf<-aggregate(df$`Var1` , by=list(Category=df$Management, Category=df$Habitat), FUN=sum)