I noticed that when using the group_by statement with summarize, I get a warning that the 'regrouping is being overridden by the .groups argument'. I found one article online that seems to indicate that a group_by statement is no longer necessary -- one just needs to include a group argument with summarize. I would like to figure out how to make this work as I'm prepping an online tutorial for students, and the less code the better. But for me, it's not working. Below is my Reprex. I'm just trying to get the mean age of each gender
library(tidyverse)
femaledata <- data.frame(age = rnorm(n=5, mean = 29, sd = 4), gender = "female")
maledata <- data.frame(age = rnorm(n=5, mean = 37, sd = 6), gender = "male")
alldata <- bind_rows(femaledata, maledata)
summarydata <- alldata %>%
summarize(gender, meanage = mean(age))
The summarydata dataframe should just have two rows (one for female and one for male) with the mean age for each. Instead my dataframe looks like this:
gender meanage
female 32.6
female 32.6
female 32.6
female 32.6
female 32.6
male 32.6
male 32.6
male 32.6
male 32.6
male 32.6
I know the group_by statement isn't complicated, but if I could get rid of a line of code, all the better.
Thanks, Wythe