Average by Group of Two Conditions

Asked 2 years ago, Updated 2 years ago, 270 views

I would like to output the summary statistics (average, maximum, minimum, etc.) for group1 and group2 for the following data frames:I would appreciate it if you could let me know.

Example)
Average value of Group A for Men =
Average value of Men in Group B =
Average value of Group A for Women =
Average value of Group B for Women =

df<-data.frame(age=1:100, group1=c(rep("Men", 50), rep("Women", 50), group2=c(rep("A", 25), rep("B", 25), rep("C", 25), rep("D", 25)))

r tidyverse

2022-10-22 09:14

1 Answers

suppressMessages (library(tidyverse))

df%>%split(list(.$group1,.$group2))%>%Filter(function(x)nrow(x)>0,.)%>%map(~summary(.$age))


2022-10-22 09:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.