Range on a field containing NAs

后端 未结 1 453
后悔当初
后悔当初 2021-02-02 04:12

I\'m using a data set where the 11th column on a csv file has numeric data. It contains some NA values too. Here is the str of the object:

str(dataheart)
 num [1         


        
相关标签:
1条回答
  • 2021-02-02 04:50

    You need

    range(x,na.rm=TRUE)
    

    see ?range

    For extra credit, here's a list of the functions in the base and stats packages that use 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"   
    

    For further consideration of which functions in R deal with NAs and how, one could do an analogous search for functions with an na.action argument (lm and friends).

    0 讨论(0)
提交回复
热议问题