在R語言中,合并兩個數據集可以使用merge()函數或者dplyr包中的left_join()、right_join()、inner_join()、full_join()等函數來實現。
merged_data <- merge(data1, data2, by = "key_column")
library(dplyr)
# left join
merged_data <- left_join(data1, data2, by = "key_column")
# right join
merged_data <- right_join(data1, data2, by = "key_column")
# inner join
merged_data <- inner_join(data1, data2, by = "key_column")
# full join
merged_data <- full_join(data1, data2, by = "key_column")