你需要
range(x,na.rm=TRUE)
看?range
base
为了获得额外的荣誉,这里是使用和stats
包中的函数列表na.rm
:
uses_na_rm <- function(x) is.function(fx <- get(x)) &&
"na.rm" %in% names(formals(fx))
basevals <- ls(pos="package:base")
basevals[sapply(basevals,uses_na_rm)]
## [1] "colMeans" "colSums"
## [3] "is.unsorted" "mean.default"
## [5] "pmax" "pmax.int"
## [7] "pmin" "pmin.int"
## [9] "range.default" "rowMeans"
## [11] "rowsum.data.frame" "rowsum.default"
## [13] "rowSums" "Summary.data.frame"
## [15] "Summary.Date" "Summary.difftime"
## [17] "Summary.factor" "Summary.numeric_version"
## [19] "Summary.ordered" "Summary.POSIXct"
## [21] "Summary.POSIXlt"
statvals <- ls(pos="package:stats")
statvals[sapply(statvals,uses_na_rm)]
## [1] "density.default" "fivenum" "heatmap" "IQR"
## [5] "mad" "median" "median.default" "medpolish"
## [9] "quantile.default" "sd" "var"
为了进一步考虑 R 中的哪些函数处理NA
s 以及如何处理,可以对带有na.action
参数(lm
和朋友)的函数进行类似的搜索。