I wrote some code to merge some columns from different data frames into a new data frame based on mapping data in one of the columns. I know that I can use the merge function for this, and now, in retrospect, I don't know why I didn't. However, it seems like the code that I wrote should work but didn't. I found a work-around which I demonstrate here. Can anyone explain why the first section doesn't work but the second one does? And, for tuning my basic R skills, are there better ways for doing this manually (i.e. not using 'merge') than how I do it? Thanks. # final resting place for data complete.data <- data.frame(positions=good.positions) j <- 1 # generate mapping information map <- match( good.positions, orig.data$positions) is.pos.present <- ! is.na(map) good.pos <- map[ is.pos.present ] ## this doesn't seem to work complete.data[is.pos.present,j] <- orig.data$values[good.pos] ## this does work tmp <- rep(NA,length(is.pos.present)) tmp[is.pos.present] <- orig.data$values[good.pos] complete.data[,j] <- z