dataframe 1 :
ID species sites count
411 Androsace halleri A24C 2
785 Bartsia alpina A28B 1
222 Carex cespitosa C97Z 3
125 Cicuta viros D47S 1
dataframe 2 :
ID species YEAR observer sites
411 Androsace halleri 2018 James A24C
785 Bartsia alpina 2019 Nikos P89I
222 Carex cespitosa 2018 Enzo Y54K
125 Cicuta viros 2020 David D47S
wanted dataframe :
ID species YEAR observer sites count sites.y
411 Androsace halleri 2018 James A24C 2
785 Bartsia alpina 2019 Nikos A28B 1 P89I
222 Carex cespitosa 2018 Enzo C97Z 3 Y54K
125 Cicuta viros 2020 David D47S 1
I did this:
wanted_dataset <- dataset_1 %>%
full_join(dataset_2, by="ID")
but I get something like this :
ID species.x sites.x count species.y YEAR observer sites.y
411 Androsace halleri A24C 2 Androsace halleri 2018 James A24C
785 Bartsia alpina A28B 1 Bartsia alpina 2019 Nikos P89I
222 Carex cespitosa C97Z 3 Carex cespitosa 2018 Enzo Y54K
125 Cicuta viros D47S 1 Cicuta viros 2020 David D47S
and I don't want the columns "species" to be repeated if all the rows of the dataframe 1 match with all the rows of the dataframe 2.
I'm aware I can do this:
wanted_dataset <- test1 %>%
full_join(test2, by=c("ID", "species"))
but my actual problem concerns 14 dataframes containing each 30 columns where one third of them share the sames names between the dataframes so I was looking for a way to match and merge automatically columns that have the same names and have the same rows.
(tell me if I'm not clear I would try to better explain my problem)