0

I have three dataframes. All have an ID number column. How can I merge the three dataframes into one by ID?

I have tried, but the data from "ant_data_session_1" are returned as NA.

all_merged_data<- ABM_maindata %>%
  left_join(esm_centralities, by="Rid") %>%
  left_join(ant_data_session_1, by="Rid")
Brage Kraft
  • 45
  • 1
  • 6
  • 1
    Unfortunately nobody will be able to help unless you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – user438383 Nov 08 '21 at 09:45
  • Have you manually verified that there exists rows (i.e. `Rid` values) in `ant_data_session_1` that also exist in `ABM_maindata`? Remember, with left_join, any rows that exist in `esm_centralities` but not in `ABM_maindata` are left. You might want to consider `full_join` or some other variants of the join-family. – MrGumble Nov 08 '21 at 09:52

1 Answers1

1

Found out that "Rid" in ABM_maindata was factor and had trailing spaces.

Fixed by importing ABM_maindata with stringsAsFactors = TRUE and ABM_maindata$Rid <- trimws(ABM_maindata$Rid, which = c("right"))

Brage Kraft
  • 45
  • 1
  • 6