Skip to content
Prev 273266 / 398503 Next

Efficient way to do a merge in R

So I give it a shot, although I don't have answers but only some ideas which avenues I would explore, not being an 
expert at all:

1. I would try to be more restrictive with the columns used for merge, trying something like
m1 <- merge( x, y, by.x = "V1", by.y = "V1", all = TRUE )

2. It may be an option to use match() directly:
indices <- match( y$V1, x$V1 )
That should give you a vector of 300,000 indices mapping the y values to their corresponding x records. I assume that 
there is always one record in y matching one record in x. You would still need to write some code to add the 
corresponding y values to a new column in x.

3. If that fails, and nobody else has a better idea, I would consider using a database engine for the job.

Again, no expert advice, just a few ideas!

Rgds,
Rainer
On Tuesday 04 October 2011 01:01:45 Aur?lien PHILIPPOT wrote: