0
test<-left_join(vol,pri,by=c('sku','year','month'))
test<-merge(x = vol, y = pri, by =c("sku","year","month"),all.x=TRUE)

I tried these two. It returns a data frame with pri's columns full of NAs. I made sure that the columns in 'by' parameter are of the same type in pri and vol Also checked a few cases within pri and vol to make sure that there are at least a few matches Could I have made any mistake? Or is there something else i can try?

vol looks something like: sku year month volume

pri looks like: sku year month size pack price

I want test to be: sku year month volume price size pack

in any order. I am getting the right structure out of the functions but the data is just NAs with no matches.

  • 1
    Please make this question *reproducible*. This includes sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`) and intended output given that input. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Sep 24 '20 at 18:51
  • most likely the column types you are trying to join on are not the same, so they don't match. Check the month and year column in particular which could be string, numeric, date, or datetime – Calum You Sep 24 '20 at 18:59
  • As i mentioned, I made sure the types matched perfectly for sku, month and year – Tharun Sriram Sep 24 '20 at 18:59
  • A left join keeps all rows in the left data frame (`vol`). Rows from the right data frame (`pri`) that match on all of the `by` columns will be included in the result with their data. Rows from the left data frame that do not have matches in the right data frame will be kept, and any columns from the right data frame will be filled out with `NA` values. Do and `inner_join` to see only the rows that match. All the rows that do not match should be `NA` values. Maybe `vol` just has way more rows. Or maybe what you think is matching isn't really... – Gregor Thomas Sep 24 '20 at 19:06
  • 1
    Also make sure that what you want to match *really matches*. If SKUs are sometimes character, sometimes numeric, sometimes have extra whitespace, sometimes have leading 0s, they may not match. As others have said, share a little data so we can see what's going on. Use `dput()` to make sure it is reproducible and the class/structure information is included. – Gregor Thomas Sep 24 '20 at 19:07
  • Tharun, thank you for editing your question, but ... that does not give us enough information to be able to help you. As I suggested before, the gold-standard of sample data is provided by either `data.frame` or `dput`, anything else is highly likely to *hide* the issues that are affecting your merge. – r2evans Sep 24 '20 at 19:09

0 Answers0