I’m having problems getting aggregate to work on a data frame that has variable names which are “numbers”. Here’s an example:
library(stringr)
# this works
df <- data.frame(x001=runif(10),x002=runif(10),category=rep(1:2,5))
aggregate(. ~ category, data=df, mean)
# this doesn't
names(df) <- str_replace(names(df),"x","")
aggregate(. ~ category, data=df, mean)
What am I doing wrong?
I agree with @orizon’s point about using non-standard names, but to answer your question, you would tick the names.
EDIT:
This would be better, and more general:
and if you really wanted bad names in your aggregation, too: