Thank you Dan and Ista! Both of you are correct, I should have used NA rather than "NA" in my example. So the correct code should be:
X <-as.data.frame(matrix(c(9, 6, 1, 3, 9, NA, NA,NA,NA,NA, 6, 4, 3,NA, NA, NA, 5, 4, 1, 3), ncol=2)) names(X)<-c("X1","X2") X$X1[is.na(X$X1)] <- X$X2[is.na(X$X1)] Where the last line replaces the missing observations of X1 by those of X2. The "if else" statement also works. Thank you very much, again! Rita -- View this message in context: http://r.789695.n4.nabble.com/Replacing-NAs-in-one-variable-with-values-of-another-variable-tp3763269p3765317.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.