2017-08-10 32 views
0

我有一个数据框在一列中有大约10,000个字,而在另一列中有相应的频率。我也有一个约600字的矢量。每个600字是数据帧中的一个字。如何从10,000字数据帧中查找600字矢量的频率?如何提取R中单词子集的词频?

+0

'match'或'merge'之间恒定。 – Gregor

+0

建议R-FAQ重复[如何加入数据](https://stackoverflow.com/q/1299871/903061) – Gregor

回答

0

使用dplyr的连接函数。

# make the 600 vector into a dataframe 
600_df <- as.data.frame(600_vec) 

# left join the two dataframes 
df <- left_join(x = 600_df, y = 10000_df, by = "word") 

其中 “字” 是变量名两个dataframes

0

在众多的解决方案,与df$words是您的data.frame的话和wordsvector作为载体的柱:

library(plyr) 
freqwords <- ddply(df, .(words), summarize, n = length(words)) #shows frequency of all the words in the data.frame 
freqwords[freqwords$words %in% wordsvector,] #keeping only the words that appear in your vector 

下一次,如果你提供一些虚拟的数据,所以我们会有所帮助可以帮助你更好。