You're just missing the data argument in your group by.
library(dplyr)
newdata <- filter(starwars,
gender == "female")
newdata <- group_by(newdata,
species)
newdata <- summarize(newdata,
mean_ht = mean(height, na.rm = TRUE))
1 Like
The error is in your second line where your group_by
does not specify the data, i.e. newdata.
You are better off using the pipe operator %>%
for such workflows.
1 Like
But in the output I don't see the gender value getting printed how can I make it happen?
I don't see the gender value getting printed in the output so how can I make it happen?
You'll need to include gender in the group_by()
function in that case, but you have already filtered gender in your first statement.
1 Like
Just on formatting of the code, typically easier to read it like this:
newdata <- filter(starwars, gender == "female") %>%
group_by(species) %>% summarize( mean_ht = mean(height, na.rm = TRUE))
ie. filter, then do, group by, then summarize
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.