r中不包括NA的列长度

Ay_M

假设我有data.frame以下内容:

   a  b c
1  5 NA 6
2 NA NA 7
3  6  5 8

我想找到每列的长度,不包括NA。答案应该看起来像

a b c 
2 1 3 

到目前为止,我已经尝试过:

 !is.na()                  # Gives TRUE/FALSE
 length(!is.na())          # 9 -> Length of the whole matrix
 dim(!is.na())             # 3 x 3 -> dimension of a matrix
 na.omit()                 # removes rows with any NA in it.

请告诉我如何获得所需的答案。

研究

或更快:

colSums(!is.na(dat))
a b c 
2 1 3 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章