[R] Quickest way to match two vectors besides %in%?

paul sorenson sourceforge at metrak.com
Tue Nov 8 21:47:08 CET 2005


Pete Cap wrote:
> Hello list,
> 
> I have two data frames, X (48469,2) and Y (79771,5).
> 
> X[,1] contains distinct values of Y[,2].
> I want to match values in X[,1] and Y[,2], then take
> the corresponding value in [X,2] and place it in
> Y[,4].
> 
> So far I have been doing it like so:
> for(i in 1:48469) {
> y[which(x[i,1]==y[,3]),4]<-x[i,2]
> }

I'm not sure but isn't that a case where merge() can help?

cheers




More information about the R-help mailing list