Mean by Group in R (2 Examples) | dplyr Package vs. Base R | group_by() & summarise_at() Functions

preview_player
Показать описание
R code of this video:

data(iris) # Load Iris data
head(iris) # First rows of Iris

aggregate(x = iris$Sepal.Length, # Specify data column
by = list(iris$Species), # Specify group indicator
FUN = mean) # Specify function (i.e. mean)

library("dplyr") # Load dplyr package

iris %>% # Specify data frame
group_by(Species) %>% # Specify group indicator
summarise_at(vars(Sepal.Length), mean) # Specify column & function

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

some of the best videos iv used and well explained. Its great how you explain everything to the side of your code in the # - easy to understand.

charliemorten
Автор

Not all heroes war caps, some of them do R tutorial for dummies who are lost in their PhD

Laurevonderweid
Автор

Legend! Love your videos.

Just the next step I am stuck with now = how do I put the group means into a column of the same dataset that is set longways (e.g., imagine person 1 has 3 responses = 4, 5, 6 [data long] so their average score is 5. How do I put their average score into a new column so I have average = 5, 5, 5 [data long] ?

leighmellish