How can I sum the number of complete cases of two columns?
With c
equal to:
a b
[1,] NA NA
[2,] 1 1
[3,] 1 1
[4,] NA 1
Applying something like
rollapply(c, 2, function(x) sum(complete.cases(x)),fill=NA)
I'd like to get back a single number, 2
in this case. This will be for a large data set with many columns, so I'd like to use rollapply
across the whole set instead of simply doing sum(complete.cases(a,b))
.
Am I over thinking it?
Thanks!
You can calculate the number of complete cases in neighboring matrix columns using
rollapply
like this: