I have this df where there are 3 colums: year, treatment/control group, and double variable.
year T/C Var
<int> <int> <dbl>
1992 0 15.5
1992 0 0.0
1993 0 17.5
1993 0 20.5
1992 1 40.5
1992 1 2.0
1993 1 27.0
1993 1 19.5
What can I do to make a table similar to this where the columns are the treatment/control, rows are the years, and the cells are populated by the mean of var for that group?
0 1
1992 mean(var(0, 1992)) mean(var(1, 1992))
1993 mean(var(0, 1993)) mean(var(1, 1993))
I tried group_by and summarise like this but I don't know how to make the T/C the columns.
df %>% group_by(year, T/C) %>% summarise(across(everything(), list(mean)))