I'm working on an assignment and wanted to double check to ensure I performed this code correctly. The question asked: What proportion of female infants were born by abdominal method of delivery?
table(SB_xlsx$sex)
##
## female male
## 320 330
table(SB_xlsx$delivery)
##
## abdominal vaginal
## 314 335
prop.table(table(SB_xlsx$sex, SB_xlsx$delivery))
##
## abdominal vaginal
## female 0.2426584 0.2503864
## male 0.2395672 0.2673879
Have I done this correctly to say the proportion of female infants that were born through abdominal means is 0.24? I wanted to double check!
EDIT: Thank you to those who helped, this was my final solution!
library(dplyr)
SB_xlsx <- SB_xlsx %>% filter(sex=="female")
prop.table(table(SB_xlsx$sex, SB_xlsx$delivery))
##
## abdominal vaginal
## female 0.492163 0.507837
CodePudding user response:
It's partially completed. You can apply a filter before calculating the proportions like this:
library(dplyr)
SB_xlsx <- SB_xlsx %>% filter(sex=="female")
prop.table(table(SB_xlsx$sex, SB_xlsx$delivery))
Now you make sure that only females are measured.