Skip to content
Prev 261621 / 398502 Next

Replacing variables in one dataset with those from another

Hi:

Letting d1 and d2 be your two data frames,
grpnum       uniqueid   x2
1      D           <NA>  276
2      B           <NA>  898
3      A GHU82RK02HD7D6  334
4      C GHU82RK02IXPC7 4077

If you want x1 to be the variable name for the new dataset, then

dmerge <- merge(d1, d2, by.x = 'x1', by.y = 'num', all.x = TRUE)[, c(2, 4, 3)]
names(dmerge)[2] <- 'x1'

HTH,
Dennis
On Wed, Jun 1, 2011 at 11:30 AM, mcginnis21 <mcginnis at montana.edu> wrote: