I am trying to use aggregate inside a function by using dplyrs {{ }} notation to select the column to aggregate on.
filter <- function(df, level) {
df <- aggregate(.~ {{level}}, data=df, FUN=sum)
return(df)
}
however I get the error
Error in model.frame.default(formula = cbind(phylum, '12K1B.txt', '12K2B.txt', :
variable lengths differ (found for '{{ level }}')
I have double checked my data and there are no missing or NA values and everything works as expected when I run it outside of the function so I am not sure what is causing the error.