Compare one group to the rest of the groups as a whole in R

Here is some sample data:

movie_df <- data.frame("ID" = c(1,2,3,4,5,6,7,8,9,10),
                        "movie_type" = c("Action", "Horror", "Comedy", "Thriller", "Comedy", 
                                         "Action","Thriller", "Horror", "Action", "Comedy"),
                        "snack_type" = c("Chocolate", "Popcorn", "Candy", "Popcorn", "Popcorn", 
                                         "Candy","Chocolate", "Candy", "Popcorn", "Chocolate"),
                        "event_type" = c("Solo", "Family", "Date", "Friends", "Solo", 
                                         "Family","Date", "Date", "Friends", "Friends"),
                        "total_cost" = c(50, 35, 20, 50, 30,
                                         60, 25, 35, 20, 50))

What I want to do is go through each column and compare each group to the rest of the groups on total_cost. For example, I want to see how movie_type == 'Action' compares to movie_type != 'Action' for total_cost. I want to do that for every type in movie_type then every type in snack_type and event_type.

What I ultimately want to get to is this where sd = Standard Deviation. Ideally this will be done by a tidyverse method (e.g. dplyr or tidyr):

> results_df
# A tibble: 11 x 11
   Group      Grp_1     Grp_2         Grp_1_mean Grp_2_mean Grp_1_sd Grp_2_sd Grp_1_n Grp_2_n Mean_Diff `t-test`
   <chr>      <chr>     <chr>              <dbl>      <dbl>    <dbl>    <dbl>   <dbl>   <dbl>     <dbl>    <dbl>
 1 movie_type Action    Rest of group       43.3       35      20.8      11.5       3       7      8.33    2.84 
 2 movie_type Horror    Rest of group       35         38.1     0        16.0       2       8     -3.12   -2.21 
 3 movie_type Thriller  Rest of group       37.5       37.5    17.7      14.6       2       8      0       0    
 4 movie_type Comedy    Rest of group       33.3       39.3    15.3      14.6       3       7     -5.95   -2.22 
 5 snack_type Chocolate Rest of group       41.7       35.7    14.4      14.8       3       7      5.95    2.26 
 6 snack_type Candy     Rest of group       38.3       37.1    20.2      12.9       3       7      1.19    0.407
 7 snack_type Popcorn   Rest of group       33.8       40      12.5      15.8       4       6     -6.25   -2.60 
 8 event_type Date      Rest of group       26.7       42.1     7.64     14.1       3       7    -15.5    -7.25 
 9 event_type Family    Rest of group       47.5       35      17.7      13.4       2       8     12.5     3.86 
10 event_type Friends   Rest of group       40         36.4    17.3      14.1       3       7      3.57    1.28 
11 event_type Solo      Rest of group       40         36.9    14.1      15.1       2       8      3.12    1.04

a solution can be found here:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.