This seems to be a very straightforward problem - but for some reason it is not working for me.
I want to aggregate by the different categories in the 9th column - "OWNRAGE.id". In other words, I want to collapse the different categories under OWNRAGE.id to a single category and sum all the values.
I used the following code
idVars <- names(df[,1:9])
dataVars <- names(df[10:15])
by_vars = idVars[ idVars != "OWNRAGE.id" ]
library(dplyr)
data_aggregated <- group_by(df, one_of(by_vars)) %>% summarise_each(funs(sum), one_of(dataVars))
The above does not work and gives me an error
Error in eval(expr, envir, enclos) :
wrong result size (0), expected 84 or 1
In addition: Warning message:
I also tried the base aggregate function
data_aggregated <- aggregate( df[ dataVars], by=as.list( data_subset[ idVars ] ), sum )
This gives me an empty data frame.
I will greatly appreciate any ideas.