[R] merge data

Chuck White chuckwhite8 at charter.net
Tue Nov 10 18:36:59 CET 2009


df1 -- dataframe with column date and several other columns. #rows >40k  Several of the dates are repeated.
df2 -- dataframe with two columns date and index. #rows ~130  This is really a map from date to index.

I would like to create a column called index in df1 which has the corresponding index from df2.

The following works:
index <- NULL
for(wk in df1$week){
    index <- c(index,df2$index[df2$week==wk])
}
and then add index to df1.

Can you please suggest a better way of doing this? I didn't think merge was suitable for this...is it? THANKS.




More information about the R-help mailing list