假设我有一个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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)