What do you want to happen when both are NA? what do you want to happen if both
have values?
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounce
You don't say what happens if both arrays have non-missing entries, but
assuming that doesn't happen:
> ifelse(is.na(xf),xg,xf)
[1] "W" "k" "h" NA "g" "r" "j" NA "v" "d" NA "v" NA "z" "r" "r" "i"
--
David L Carlson
Associate Professor of Anthropolo
I made different assumptions than Josh.
xf<-c("W",NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)
xg<-c(NA,"k","h",NA,"g","r","j",NA,"v","d",NA,"v",NA,"z","r","r","i")
xf
xg
unlist(apply(cbind(xf,xg), 1, function(x) x[!is.na(x)]))
as.vector(unlist(apply(cbind(xf,xg), 1, function(x) x[!is.na(x)]))
Hi,
You did not specify what assumptions you can make about xf and xg
(such as will they have identical lengths and is it possible both
could contain nonmissing values in the same element?), but this seems
a straightforward approach in your little example:
index <- is.na(xf)
xf[index] <- xg[index
4 matches
Mail list logo