我有2个数据框:
df1
Syllable Duration
Bis 0.18
Zeks 0.34
Ben 0.11
df2
Syllable Duration Pitch
Bis 0.18 78
Zeks 0.34 67
Bs 0.19 34
Ben 0.11 69
我需要得到一个像这样的新数据框:
df3
Syllable Duration Pitch
Bis 0.18 78
Zeks 0.34 67
Ben 0.11 69
我尝试了很多东西,但没有什么能让我得到我想要的东西。任何帮助对我都有价值。
这是我尝试过的事情之一:
df1$Pitch <- df1$Pitch[match(df2$Syllable[df2$Duration],df1$Syllable[df1$Duration])]
答案 0 :(得分:1)
The comments are right. But if you have duplicates in your data, it can cause multiplications of rows in your outcome. Use this to get rid of duplicates:
df3 <- merge(df2, df1[!duplicated(df1$Syllable),], by="Syllable")