I have data that includes a treatment group, which is indicated by a 1, and a control group, which is indicated by a 0. This is all contained under the variable treat_invite. How can I separate these and take the mean of pct_missing for the 1's and 0's? I've attached an image for clarification.
Asked
Active
Viewed 51 times
0
-
I have no idea what you mean by "*How can I separate these and include the rest of the data?*" Are you just trying to sort a dataset so all the 0's are together, then all the 1's? – thelatemail Apr 24 '19 at 02:58
-
Yes, but I want to take the mean of pct_missing of only the 1's and the mean of pct_missing of only the 0's – Anthony Trinh Apr 24 '19 at 03:03
-
Can you provide a reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Apr 24 '19 at 04:12
1 Answers
0
assuming your data frame is called df
:
df <- df %>% group_by(treat_invite) %>% mutate(MeanPCTMissing = mean(PCT_missing))
Or, if you want to just have the summary table (rather than the original table with an additional column):
df <- df %>% group_by(treat_invite) %>% summarise(MeanPCTMissing =
mean(PCT_missing))

Omry Atia
- 2,411
- 2
- 14
- 27