-2

I would like to do a vlookup a lookup table in R, hence would like to use merge for that.

The data table looks like this:

enter image description here

The mapping table looks like this:

enter image description here

I want to do a vlookup based on the id_type column and type of asset.

My code looks as such:

base1 <- (merge(MappingTable, inputData, by = 'Id_type'))

When I do so, I get this error:

Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column

Need some guidance on this.

smci
  • 32,567
  • 20
  • 113
  • 146
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • 1
    There is no `Id_type` in the second dataset – akrun Oct 22 '18 at 07:01
  • 2
    `base1 <- (merge(MappingTable, inputData,by.x="Type Of Asset",by.y="Id_type"))` – jyjek Oct 22 '18 at 07:03
  • 2
    Don't post pictures, post real data pls! – vaettchen Oct 22 '18 at 07:18
  • "VLOOKUP" is Excel for "join/merge". You want to join on **one** column which has different names in the left and right tables (`by.x, by.y`), **not on two columns** (which is a pretty rare thing to need to do). – smci Oct 22 '18 at 07:31

1 Answers1

0

@lakesh u can do with dplyr package also with full_join :

 library(dplyr)
 base1<-full_join(MappingTable,inputData,by=c("Type Of 
           Asset","Id_type"),all=TRUE)%>%arrange(Idenitifier) ##if u want to ##make order by something use **arrange**
sai saran
  • 737
  • 9
  • 32