Suppose X and Y are two data frames with the same structures, variable
names and dimensions but with different data and different patterns of
missing. I want to replace missing values in Y with corresponding values
from X. I'll construct a simple two-by-two case:
X -
On Thu, 22 Jan 2009, Mike Miller wrote:
Suppose X and Y are two data frames with the same structures, variable
names and dimensions but with different data and different patterns of
missing. I want to replace missing values in Y with corresponding
values from X. I'll construct a simple
How about this:
Y - as.data.frame(matrix(c(c,d,NA,4),2,2), stringsAsFactors=FALSE)
X - as.data.frame(matrix(c(a,b,1,2),2,2), stringsAsFactors=FALSE)
Y
V1 V2
1 c NA
2 d4
X
V1 V2
1 a 1
2 b 2
Y[] - lapply(seq(ncol(Y)), function(.col){
+ ifelse(is.na(Y[,.col]), X[,.col],
3 matches
Mail list logo