문제

I am working on the data frame called "juul" that can be found in library(ISwR). How can I re-write the following expression: selection= juul[juul$sex==2 & juul$tanner>2,] so that NA is excluded in the criteria?

도움이 되었습니까?

해결책

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])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top