Skip to content
Back to formatted view

Raw Message

Message-ID: <20091110123659.3XYGB.8154939.root@mp08>
Date: 2009-11-10T17:36:59Z
From: Chuck White
Subject: merge data

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.