0

I have the following two columns:

e_2020_certified_Machines_Per_Jurisdiction_count_per_state: enter image description here

And e_2016_certified_Machines_Per_Jurisdiction_count_per_state:

enter image description here

I would like to merge these two dataframes together so that it looks like this: (Sample data)

enter image description here

I have tried numerous things including: 1: Using the select function; 2: Merging the dataframes 3: Creating a new dataframe and inserting the data through the SQLDF package

I either get duplicated data, data that is overwritten or dataframes where 2020 gets replaced in its entirety by 2016 etc.

Help would be greatly appreciated. I've been at this for a few hours now.

I'm very sorry if this is a duplicate, I couldn't find a question similar to this on stackoverflow which actually solved the problem.

If I manage to find the answer in the meantime I'll make sure to post it as well.

Thank you very much and have a nice day!

  • Please post your data as copy/pasteable text, not as pictures. – Gregor Thomas Dec 02 '21 at 19:41
  • 1
    It's hard to see from the images, but if you want to essentially "stack" one data frame on top of the other and they already have the same columns `rbind(data1, data2)`. Though if the rows are unique, then `merge(data1, data2, all = TRUE)` should work just as well. – Gregor Thomas Dec 02 '21 at 19:43
  • @GregorThomas Your solution worked, THANK YOU! I didn't put all = TRUE at the end of the merge, that is why it didn't work. – JustAnotherPatrick Dec 02 '21 at 20:09
  • You might want to read about [different types of joins](https://www.w3schools.com/sql/sql_join.asp) It will teach you standard language to talk about (and search for help) on problems like this. – Gregor Thomas Dec 02 '21 at 21:45

1 Answers1

0

Solution:

Thanks to @GregorThomas for providing the answer.

This problem was solved with the following command:

merge(data1, data2, all = TRUE)