Re: [R] combining strings

2011-06-17 Thread Greg Snow
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

Re: [R] combining strings

2011-06-17 Thread David L Carlson
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

Re: [R] combining strings

2011-06-16 Thread Richard M. Heiberger
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)]))

Re: [R] combining strings

2011-06-16 Thread Joshua Wiley
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