[R] data-management: Rowwise NA

David S Freedman dxf1 at cdc.gov
Thu Jun 3 21:47:25 CEST 2010


you probably want to use the apply function:

d=sample(1000,500); 
d[sample(500,50)]<-NA; #put 50 NAs into the data
d=data.frame(matrix(d,ncol=50)); 
names(d)=paste('var',1:50,sep='.')
d
apply(d,1,sum) #are any of the row values NA ?
apply(d,2,function(x)sum(is.na(x))) #how many values for each of the 50
variables are NA ?

David Freedman, CDC
-- 
View this message in context: http://r.789695.n4.nabble.com/data-management-Rowwise-NA-tp2242232p2242260.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list