Determine the number of NA values in a column

后端 未结 14 1479
眼角桃花
眼角桃花 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:33

    If you are looking for NA counts for each column in a dataframe then:

    na_count <-sapply(x, function(y) sum(length(which(is.na(y)))))
    

    should give you a list with the counts for each column.

    na_count <- data.frame(na_count)
    

    Should output the data nicely in a dataframe like:

    ----------------------
    | row.names | na_count
    ------------------------
    | column_1  | count
    

提交回复
热议问题