在使用negated is.na()与which()组合时,应该在which()函数中添加na.last=NA参数。
示例代码如下:
创建一个包含NA的向量
x <- c(1, 2, NA, 4, 5)
使用negated is.na()与which()组合
which(!is.na(x)) # 输出结果为1 2 4 5
使用na.last=NA参数
which(!is.na(x), na.last=NA) # 输出结果为1 2 4 5
通过添加na.last=NA参数,我们可以确保使用negated is.na()与which()组合时得到一致的结果。