1

I have 2 data frames as given below. I want to append the 4th column of DS2 in DS1 based on the look up value of column 2 and column 3.

DS1

Entity  Service Type    Service Description Unit Price Incurred Volume    Total Service Charge in USD 
Entity1 WIRE & OTHER FUNDS TRNSF SVCS   CPO GP CUST MNT TEMP STORAGE    0.15    1024    153.6
Entity1 PAYMENT TRANSACTIONS    WIRE-HVC-LOCAL PAYMENT STP DR SHA   5.62    459 2579.58
Entity1 PAYMENT TRANSACTIONS    WIRE-HVC-LOCAL PAYMENT STP DR OUR   8.27    88  727.76
Entity1 PAYMENT TRANSACTIONS    FOREIGN WIRE PAYMENT STP DR SHA 19  40  760

DS2

Entity  Service Type    Service Description Unit Price Agreed
Entity1 WIRE & OTHER FUNDS TRNSF SVCS   CPO GP CUST MNT TEMP STORAGE    0.15
Entity1 PAYMENT TRANSACTIONS    WIRE-HVC-LOCAL PAYMENT STP DR SHA   5.62
Entity1 PAYMENT TRANSACTIONS    WIRE-HVC-LOCAL PAYMENT STP DR OUR   8.27
Entity1 PAYMENT TRANSACTIONS    FOREIGN WIRE PAYMENT STP DR SHA 15

I tried bcagd <- join(ctse1,bcagd, by = "Service Type")but it is throwing an error unused argument. I have many line in the datasets. Please suggest the correct function to use.

  • Please format your `data.frame` so you can tell where one column stops and the next starts. Even better, paste the output of `dput` – manotheshark Jan 11 '17 at 06:07
  • I tried using merge but the I want the output file with line items which were not found in the DF2 with an NA or some flag in the unit.price.agreed column. I am new to SO, so might go go bad in formatting the question. I used merge bcagd2 <- merge(bc2, bcagd, by = c("Entity","Service.Type", "Service.Description")) – Abhishek Vedula Jan 11 '17 at 06:24
  • Here the line items for which the match is not found are going missing – Abhishek Vedula Jan 11 '17 at 06:26
  • Look at the linked question to read the different type of joins. Or type `?merge` and read about `all` – manotheshark Jan 11 '17 at 06:49
  • You can use `left_join` i.e. `library(dplyr);left_join(DS1, DS2, by = names(DS1)[1:3])` – akrun Jan 11 '17 at 07:00
  • Thanks, thats very useful – Abhishek Vedula Jan 11 '17 at 09:12

0 Answers0