Determine the number of NA values in a column

后端 未结 14 1461
眼角桃花
眼角桃花 2020-12-02 04:17

I want to count the number of NA values in a data frame column. Say my data frame is called df, and the name of the column I am considering is

14条回答
  •  北海茫月
    2020-12-02 04:54

    Similar to hute37's answer but using the purrr package. I think this tidyverse approach is simpler than the answer proposed by AbiK.

    library(purrr)
    map_dbl(df, ~sum(is.na(.)))
    

    Note: the tilde (~) creates an anonymous function. And the '.' refers to the input for the anonymous function, in this case the data.frame df.

提交回复
热议问题