How to join data frames based on multiple columns in the R programming language. More details:
https://statisticsglobe.com/merge-data-frames-by-two-id-columns-in-r
R code of this video:
data1 <- data.frame(ID1 = 1:5, # Create first data frame
ID2 = letters[1:5],
x1 = c(4, 1, 6, 7, 8),
x2 = 9)
data2 <- data.frame(ID1 = 3:7, # Create second data frame
ID2 = letters[3:7],
y1 = c(4, 4, 5, 1, 1),
y2 = 5)
data_merge1 <- merge(data1, data2, by = c("ID1", "ID2")) # Applying merge() function
install.packages("dplyr") # Install dplyr package
library("dplyr") # Load dplyr package
data_merge2 <- inner_join(data1, data2, by = c("ID1", "ID2")) # Applying inner_join() function
Follow me on Social Media:
Facebook:
https://www.facebook.com/statisticsglobecom/
Patreon:
https://www.patreon.com/statisticsglobe
Pinterest:
https://www.pinterest.de/JoachimSchork
Reddit:
https://www.reddit.com/user/JoachimSchork
Twitter:
https://twitter.com/JoachimSchork
Тэги:
#statistics_globe #statisticsglobe.com #statistical_programming #r_programming #statistics #r_programming_language #r_statistics #rstudio #r_language #r_tutorial #learn_r #r_code #r_programming_tutorial #merge_data_frames #ID_columns #merge_function #join_function #inner_join_function #dplyr_package #two_id_columns