Count number of non-NA values for every column in a dataframe

后端 未结 3 1767
刺人心
刺人心 2020-12-22 09:46

I have a big dataset that contains a lot of NAs and some non-Na values. At the moment I count my non-NA values for each column like this:



        
3条回答
  •  孤城傲影
    2020-12-22 09:57

    With dplyr, that would be:

    library(dplyr)
    
    df %>%
    summarise_all(funs(sum(!is.na(.)))
    

    The advantage of that approach is that you can use group_by before, and that you don't need to care about column names (it just summarizes all of them).

提交回复
热议问题