2

Hi guys this is my first post, i need help summing the number of NA's in a few vectors

for example..

c1<-c(1,2,NA,3,4)
c2<-c(NA,1,2,3,4) 
c3<-c(NA,1,2,3,4) 

how would i get a result that only sums the number of NA's in the vector?

the.result.i.want<-c(2,0,1,0,0)
Matt.G
  • 95
  • 1
  • 1
  • 4
  • Maybe relevant: [There is pmin and pmax each taking na.rm, why no psum?](http://stackoverflow.com/questions/13123638/there-is-pmin-and-pmax-each-taking-na-rm-why-no-psum) – Frank Oct 17 '13 at 06:12

1 Answers1

4

Your question isn't well-phrased, but it looks like you want the result of colSums used with rbind and is.na:

> colSums(is.na(rbind(c1, c2, c3)))
[1] 2 0 1 0 0
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
  • hey @user2889147: Oddly enough, this is almost exactly the answer I posted when this fellow (mattbju2013) posted this to r-help. I used apply instead of colSums but it's the same operation. – Carl Witthoft Oct 17 '13 at 11:38