Closed jasmincantzler closed 8 years ago
You want to do something like
library(dplyr)
summary_df <- df %>%
group_by(country) %>%
summarise(
mean = mean(age,na.rm=TRUE)
)
It says I cannot group by "country" because its a factor:
Fehler in UseMethod("groupby") : nicht anwendbare Methode für 'groupby' auf Objekt der Klasse "factor" angewendet
Oh, weird. What about group_by(as.character(country))?
Nope :( group_by and as.character don't want to go together (group_by(as.character(mydata$Country)))
Fehler in UseMethod("groupby") : nicht anwendbare Methode für 'groupby' auf Objekt der Klasse "character" angewendet
Ah, I have already supplied the dataframe as the first argument to dplyr's group by function by piping it (%>%), so you don't need mydata$Country, just Country.
THANK YOU!
Dear all,
Since some of you are way more familiar with R than I am, I am putting this out here in the hope that someone can restore my sanity. I try to generate a basic summary statistics table. In preparation I want to calculate the mean grouped by a factor variable; so the mean age for example per country variable.
If someone could help me out I would appreciate it greatly. R and I are not yet friends :(
(just in case you want to have a look: https://github.com/jasmincantzler/TaxMorale/blob/master/Assignment%203/Data%20Analysis.R)