R 从字符向量创建自定义词典
我试图使用dfm_lookup()在语料库中查找特定的单词 我正在为dfm_loopup()所需的词典而苦苦挣扎 我创建了一个名为“words”的字符向量,其中包含所有应该进入字典的单词R 从字符向量创建自定义词典,r,text-mining,quanteda,R,Text Mining,Quanteda,我试图使用dfm_lookup()在语料库中查找特定的单词 我正在为dfm_loopup()所需的词典而苦苦挣扎 我创建了一个名为“words”的字符向量,其中包含所有应该进入字典的单词 dict <- dictionary(list(words)) dictionary需要一个列表,因此在使用dictionary()之前,我将从字符向量创建一个列表 要获得dictionary()的正确输出,我必须在list命令中更改什么 是否有更简单的版本来查找dfm中的特定单词?因为使用tm()软件
dict <- dictionary(list(words))
dictionary需要一个列表,因此在使用dictionary()之前,我将从字符向量创建一个列表
要获得dictionary()的正确输出,我必须在list命令中更改什么
是否有更简单的版本来查找dfm中的特定单词?因为使用tm()软件包非常简单。我认为您需要在列表中命名项目,以便使用字典和
quanteda
。以下是一个例子:
library(quanteda)
words = c("cat","dog","bird")
word.list = as.list(words)
names(word.list) = words
dictionary(word.list)
Dictionary object with 3 key entries.
- [cat]:
- cat
- [dog]:
- dog
- [bird]:
- bird
正如文档和错误提示的那个样,您需要命名列表的元素:字典(list(words=words))应该会有所帮助。如果不仔细阅读,非常感谢,这对我帮助很大@班夫老板122:不客气,很高兴我能帮上忙:)输入
dictionary(x)
中的x
需要是一个命名列表,如?dictionary
中所述。所以字典(列表(mykey=c(“value1”、“value2”))
等等。
library(quanteda)
words = c("cat","dog","bird")
word.list = as.list(words)
names(word.list) = words
dictionary(word.list)
Dictionary object with 3 key entries.
- [cat]:
- cat
- [dog]:
- dog
- [bird]:
- bird