0

I have the following data and I would like to calculate IQR for only for those whose sex is equal to 1.

enter image description here

I have tried

if(Agogo$sex_2015==2) { IQR(Agogo$bmi) }

Is there any way to do this using ifelse or any other condition?

Andrea M
  • 2,314
  • 1
  • 9
  • 27

1 Answers1

0

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))
Fatih Aslan
  • 108
  • 3