我对R语言非常陌生。我有一个似乎无法解决的简单问题: 我有两个2D数据集,分别是航空公司和航班。我想用数据框机票中的全名替换数据框航班中的“两个字母的缩写”。在航空公司数据框中,缩写和全名具有相同的行,但没有相同的列。
有人可以给我任何建议吗?我一直在尝试将其放入for循环中并使用功能gsub()
,但尚未解决。任何帮助将是救生员!
答案 0 :(得分:1)
library(dplyr)
combo <- flights %>%
left_join(airlines)
答案 1 :(得分:0)
newdf <- merge(x = flights,
y = airlines,
by.x = 'two_letter_carrier_abbreviation', #abbreviation column from flights
by.y = 'two_letter_carrier_abbreviation', #abbreviation column from airlines
all.x = TRUE, #keep all rows in flights
all.y = FALSE) #don't add full names that are not found in flights
newdf$two_letter_carrier_abbreviation <- NULL #remove the abbreviation column