Here you go.
library(dplyr)
Mean_of_a_group <- dataset %>% group_by(age_group) %>% summarize(happy = mean(happy))
I suggest using ggplot2 to do what you want here.
ggplot(data = Mean_of_a_group, aes(age_group, happy))+ geom_point
Dummy example
library(ggplot2)
ggplot(aes(x = disp, y= mpg), data = mtcars)+
geom_smooth(aes(colour = "red"), data = mtcars, stat = "smooth", formula = y ~ x , se = FALSE)+
geom_smooth(aes(coluor = "blue"), data = mtcars, stat = "smooth", formula = y ~ poly(x,2), se = FALSE)+
geom_point()
6
solved How to calculate the mean of a group in R [closed]