I am trying to merge together 8 dataframes into one, matching against the row names.
Examples of the dataframes:
DF1
| Arable and Horticulture | |
|---|---|
| Acer | 100 |
| Achillea | 90 |
| Aesculus | 23 |
| Alliaria | 3 |
| Allium | 56 |
| Anchusa | 299 |
DF2
| Improved Grassland | |
|---|---|
| Acer | 12 |
| Alliaria | 3 |
| Allium | 50 |
| Brassica | 23 |
| Calystegia | 299 |
| Campanula | 29 |
And so on for a few hundred rows for different plants and 8 columns of different habitats. What I want the merged frame to look like:
| Arable and Horticulture | Improved Grassland | |
|---|---|---|
| Acer | 100 | 12 |
| Achillea | 90 | 0 |
| Aesculus | 23 | 0 |
| Alliaria | 3 | 3 |
| Allium | 56 | 50 |
| Anchusa | 299 | 0 |
| Brassica | 0 | 23 |
| Calystegia | 0 | 299 |
| Campanula | 0 | 29 |
I tried merging
PolPerGen <- merge(DF1, DF2, all=TRUE)
But that does not match up the row name and dropped them entirely in the output
| Arable and Horticulture | Improved Grassland | |
|---|---|---|
| 1 | 100 | NA |
| 2 | 90 | NA |
| 3 | 23 | NA |
| 4 | 2 | NA |
| 5 | 56 | NA |
| 6 | 299 | NA |
| 7 | NA | 12 |
| 8 | NA | 3 |
| 9 | NA | 50 |
| 10 | NA | 23 |
| 11 | NA | 299 |
| 12 | NA | 29 |
I am completely out of ideas, any thoughts?
rownames_to_column()and the join should work