Hi, every time I merge files containing the same variables, R creates their copies by adding .x, .y etc.
I have these 3 simple files, which I am merging:
File1 <- data.frame(
stringsAsFactors = FALSE,
Code = c(8190, 8057, 8038, 8173, 8013, 3453, 3453),
Score = c(1, 2, 3, 4, 5, 6, 7),
Brand = c("aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg"),
Year = c(2023, 2023, 2022, 2023, 2022, 2021, 2023)
)
File2 <- data.frame(
stringsAsFactors = FALSE,
CodeNumber = c(8190, 8057, 8038, 8173, 8013),
Gender = c("Male", "Female", "Female", "Male", "Male"),
Brand = c("aaa", "bbb", "ccc", "ddd", "eee"),
Year = c(2023, 2023, 2022, 2023, 2022)
)
File3 <- data.frame(
stringsAsFactors = FALSE,
MainCode = c(8038, 8173, 8013, 3453, 3453),
Brand = c("ccc", "ddd", "eee", "fff", "ggg"),
Year = c(2022, 2023, 2022, 2021, 2023),
City = c("London", "Paris", "London", "London", "Warsaw"),
Country = c("UK", "France", "UK", "UK", "Poland")
)
library(dplyr)
all.files <- File1 %>%
left_join(File2, by = c("Code" = "CodeNumber"), multiple="all") %>%
left_join(File3, by = c("Code" = "MainCode"), multiple="all")
all.files
Is there a way of removing repeated variables from merging? In this example I want to keep just the original Brand and Year from the main File1.
Is it possible?