简体   繁体   中英

Using conditional selection to create a subset of data

I have a dataset called dietox which has missing values (NA) for the Feed variable. I need to use conditional selection to create a subset of the data for which the rows with missing values are deleted.

The code I tried was:

dietox[!is.NA[dietox$Feed, ] 

... but am not sure if that is right to create a subset.

dput(head(dietox)) 

dietox <- structure(list(Weight = c(26.5, 27.59999, 36.5, 40.29999, 49.09998, 
             55.39999), Feed = c(NA, 5.200005, 17.6, 28.5, 45.200001, 56.900002 ),
             Time = 1:6, Pig = c(4601L, 4601L, 4601L, 4601L, 4601L, 4601L ),
             Evit = c(1L, 1L, 1L, 1L, 1L, 1L), Cu = c(1L, 1L, 1L, 1L, 1L, 1L),
             Litter = c(1L, 1L, 1L, 1L, 1L, 1L)),
            .Names = c("Weight", "Feed", "Time", "Pig", "Evit", "Cu", "Litter"),
            row.names = c(NA, 6L), class = "data.frame")

你有正确的想法,但is.na是一个函数,因此需要与括号一起使用。

dietox[!is.na(dietox$Feed), ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM