How to count number of Numeric values in a column

后端 未结 5 1990
轻奢々
轻奢々 2021-02-06 05:24

I have a dataframe, and I want to produce a table of summary statistics including number of valid numeric values, mean and sd by group for each of three columns. I can\'t seem

5条回答
  •  执笔经年
    2021-02-06 05:47

    What are "blank values" and "text values"? If you have numeric vector then you could have NA's (is.na()), Inf's (is.infinite()), NaN's (is.nan()) and "valid" numeric values.

    For "valid" numeric values (in the sense above) you could use is.finite():

    is.finite(c(1,NA,Inf,NaN))
    # [1]  TRUE FALSE FALSE FALSE
    sum( is.finite(c(1,NA,Inf,NaN)) )
    # [1] 1
    

    So colSums(is.numeric(x)) could be done like colSums(is.finite(x)).

提交回复
热议问题