-1

I'm new to R so bear with me..

I have one table that looks like this (hundreds of rows long)

Col1 Col2   
1       1
16      6
36      3
5       8
2       26

... ...

My second Table looks likes this (has over 600 rows)

Col1   Col2    Output Column
1       1          849
29      3          348
4       4          584
5      36          373 
36      36        1902

I need to match Col 1 and Col2 in each table so that the combination of unique combination of Col1 and Col2 in table 2 returns the value in the Output column of Table 2.

I know I could spend hours writing a nested ifelse statements but there has to be a more efficient way to do this.

Any help is appreciated, even if you could just provide some stuff to look into.

Psidom
  • 209,562
  • 33
  • 339
  • 356
shea
  • 3
  • 4
  • 3
    You are looking for a `merge`. something like `merge(df1, df2, by = c("Col1", "Col2"))` should give you what you want. – Psidom May 27 '16 at 14:31

1 Answers1

0

Dplyr allows you to join on multiple columns so it would look something like this:

library(dplyr    
left_join(mtcars, mtcars2, by = c("mpg" = "mpg", "cyl" = "cyl"))
Shorpy
  • 1,549
  • 13
  • 28