We’ll calculate SDO means grouped by condition here:
sdo_mean_by_condition <- analysis_data %>%
group_by(Condition) %>%
summarise(mean(SocialDominance, na.rm=TRUE))
Code translation: We make a variable. To fill it,we tell R to look at the data in the “analysis_data” dataframe, then say we’re going to group a column calculation by the levels of the “Condition” column with the group_by() command. Then we give R the column calculation we want: a printout of the mean of the SocialDominance column. We can do the same with standard deviations:
sdo_sd_by_condition <- analysis_data %>%
group_by(Condition) %>%
summarise(sd(SocialDominance, na.rm=TRUE))
If you run a multiple regression or factorial ANOVA, you may want things broken down by multiple groups. You can do this with basically the same commands like so:
sdo_mean_by_condition_party <- analysis_data %>%
group_by(Condition, PoliticalParty) %>%
summarise(mean(SocialDominance, na.rm=TRUE))
Code translation: In the second step of the grouping, where we tell R which variables we want to group our calculation by, we can split things up into further groups with a comma between the multiple column names. Here, we tell R we want to split the data up by condition, then split that split-up data by political party. So we end up with 12 groups (3 condition groups x 4 political party options).