答案 0 :(得分:59)
将is.na
与矢量索引
x <- c(NA, 3, NA, 5)
x[!is.na(x)]
[1] 3 5
我也将尊敬的绅士/女士推荐给优秀的R介绍性手册,特别是Section 2.7 Index vectors; selecting and modifying subsets of a data set
答案 1 :(得分:34)
除了@Andrie的回答,您还可以使用na.omit
x <- c(NA, 3, NA, 5)
na.omit(x)
[1] 3 5
attr(,"na.action")
[1] 1 3
attr(,"class")
[1] "omit"