Counting non NAs in a data frame; getting answer as a vector

前端 未结 4 780
走了就别回头了
走了就别回头了 2020-12-05 00:23

Say I have the following R data.frame ZZZ:

( ZZZ <- structure(list(n = c(1, 2, NA), m = c(6, NA, NA), o = c(7, 8, 
8)), .Names = c(\         


        
4条回答
  •  悲&欢浪女
    2020-12-05 01:02

    If you only want the sum total of NAs overall, then sum() with !is.na() will do it:

    ZZZ <- data.frame(n = c(1, 2, NA), m = c(6, NA, NA), o = c(7, 8, 8))
    sum(!is.na(ZZZ))
    

提交回复
热议问题