0

So I want to create a tibble with sex distribution (or N) and respective percentages for different categories.

id <- c(1,2,3,4,5,6,7,8)
id_cat <- c(1,1,1,2,2,3,3,3)
sex <- c(0,0,1,1,0,1,0,1)
dis_cat <- c(1, 1, 2, 2, 2, 3, 3, 4)
measurement <- c(10, 13, NA,13, 12, 11, 14, NA)
myData <- data.frame(id, id_cat, sex, dis_cat, measurement)
myData

I am trying to use this but not working:

library(dplyr) 
myData %>% group_by(id_cat, sex) %>% summarise(N_sex= table(id, exclude = NA),
                                  Prop_sex= prop.table(table(id, exclude= NA)))

Is there a better way?

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
PriyamK
  • 141
  • 10

0 Answers0