I want to relate two data-frames with different size.
A simplified example of my data is as follow:
unigrams = c("the", "one", "can", "just","know", "now", "time", "but")
uni.freq = c(1304, 802, 715, 686, 428, 413, 663, 320)
bigrams = c("know i", "now i", "time i", "but i")
first.word = c("know", "now", "time", "but")
bi.freq = c(60, 58, 57, 56)
df.unigrams = data.frame(unigrams, uni.freq)
df.bigrams = data.frame(bigrams, bi.freq, first.word)
I want to add a column to df.bigrams, to show the frequency of words in the df.unigrams data-frame so it looks like this:
bigrams bi.freq first.word freq
1 know i 60 know 428
2 now i 58 now 413
3 time i 57 time 663
4 but i 56 but 320
I have tried a few things (grep, subsetting), but no luck. Any help for this beginner will be much appreciated.
df.bigrams$freq = subset(df.unigrams, df.unigrams$unigrams == df.bigrams$first.word)