[R] Strange behavior with merging algorithm

From: Gene <gene02_rsigmac_at_smalltime.com>
Date: Fri 19 May 2006 - 10:15:02 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 19 10:21:27 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 19 May 2006 - 12:10:13 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.