I have 2 vectors, for example:
A <- c(1,2,NA,NA,NA,NA,7) B <- c(NA,NA,3,4,NA,NA,7)
I would like to combine them so that the resulting vector is
1,2,3,4,NA,NA,-1
it
when only 1 value (for example, X) exists in any vector at position i (the other is NA), the new vector should take the value X at position i.
when both values ββare NA at position i, the new vector should take the value NA at position i
when both vectors have a value at position i, the new vector should take the value -1 at position i.
I can easily do this with a loop, but it is very slow on a large dataset, so can anyone provide a quick way to do this?
Robert Long
source share