[R] NA values trimming

nyk nick at nyk.ch
Mon Jul 6 10:58:41 CEST 2009


Thanks a lot, this works! The one I used before was wrong:
> data_matrix
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1   NA    1    1
[2,]    2    2    2    2    2
[3,]    3    3    3    3    3
[4,]   NA   NA   NA   NA   NA
[5,]    5    5    5    5    5
[6,]   NA    6    6   NA    6
[7,]   NA   NA   NA   NA   NA
> nas1a <- apply(data_matrix,1,function(x)sum(is.na(x))/nrow(data_matrix))
> nas1b <- rowMeans(is.na(data_matrix)) 
> nas1a
[1] 0.1428571 0.0000000 0.0000000 0.7142857 0.0000000 0.2857143 0.7142857
> nas1b
[1] 0.2 0.0 0.0 1.0 0.0 0.4 1.0

-- 
View this message in context: http://www.nabble.com/NA-values-trimming-tp24339399p24351956.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list