I have a categorical covariate data summary as below:
df <-
STUDY COV FLAG Freq
1 SEX 1 12
1 SEX 2 15
2 RACE 1 5
2 RACE 2 10
2 RACE 3 15
I want to make a summary by STUDY
and COV
to facilitate generating an rtf table. This the output that i would like to have is this.
dfout <-
STUDY COV RATIO
1 SEX 12:15
2 RACE 5:10:15
I tried using this but i know it is getting no where
library(dplyr)
dfout<- df%>%
group_by(STUDY,COV) %>%
summarise(RATIO=paste(Freq,":",lag(Freq)))
i am using Rstudio.