I have the following data and I would like to calculate IQR for only for those whose sex is equal to 1.
I have tried
if(Agogo$sex_2015==2) { IQR(Agogo$bmi) }
Is there any way to do this using ifelse or any other condition?
I have the following data and I would like to calculate IQR for only for those whose sex is equal to 1.
I have tried
if(Agogo$sex_2015==2) { IQR(Agogo$bmi) }
Is there any way to do this using ifelse or any other condition?
I'm assuming you want the get IQR of bmi
library(dplyr)
bmi<- sample(100,10)
edu_mo<-sample(50,10)
sex<-sample(2,10,replace= TRUE)
n<-data.frame(bmi,edu_mo,sex)
n %>%
filter(sex == 1) %>%
summarize(IQR = IQR(bmi))