使用向量索引和is.nax <- c(NA, 3, NA, 5) x[!is.na(x)] [1] 3 5 我还向尊敬的先生/女士推荐优秀的R语言入门手册,特别是第2.7节 索引向量; 选择和修改数据集的子集。
除了@Andrie的答案外,您还可以使用na.omitx <- c(NA, 3, NA, 5) na.omit(x) [1] 3 5 attr(,"na.action") [1] 1 3 attr(,"class") [1] "omit"
?NA
,其中描述了is.na
的行为并在“参见”部分中列出了na.omit
。 - Joshua Ulrichhablar
包中的s
。这样做:s(c(NA, 3, NA, 5)) 将返回 3 5。 - davsjob