0

I have one dataset and multiple other subdatasets, different in size which all have key ID column to link with each other. What I want to do is just copy values from subdatasets into main one everytime in new column with just calling the dataframe and specific column names of subdatasets. I know it's just simple LOOKUP formula in Excel, but due to large size of data I have to do it in R (I have looked for similar questions here but could not find quite exactly what I was looking for). For example:

 > dfmain    > dfsub1             > dfsub2                          > dfmain
   carID       carID  carsize       carID  carcapacity                carID  carsize  carcapacity
   1           1      Small         1      41                         1      Small    41
   1           2      Compact       2      56                         1      Small    41
   1                                                     >>>>>>>>>>   1      Small    41
   2                                                                  2      Compact  56
   2                                                                  2      Compact  56
  • Does this answer your question? [How to do vlookup and fill down (like in Excel) in R?](https://stackoverflow.com/questions/15303283/how-to-do-vlookup-and-fill-down-like-in-excel-in-r) – jogo Mar 11 '20 at 11:06

1 Answers1

2

This should do:

library(tidyverse)

dfmain <- dfmain %>% left_join(dfsub1) %>% left_join(dfsub2)

see here for details on left_join.

Wolfgang Arnold
  • 1,252
  • 8
  • 17