You can do that with:
selection <- na.omit(juul[juul$sex==2 & juul$tanner>2,])
However, this returns a dataframe with 0
observations. When looking at the result of:
selection <- juul[juul$sex==2 & juul$tanner>2,]
you can see why. The variable juul$testvol
has only NA's for this subset. Using na.omit
will therefore exclude all the observations from this subset. You can prevent that by excluding the juul$testvol
from the subset with:
selection <- na.omit(juul[juul$sex==2 & juul$tanner>2,c(1:5)])
or
selection <- na.omit(juul[juul$sex==2 & juul$tanner>2,-6])