这是我的代码
ny <- read.csv2("nyt.csv", sep = "t", header = T)
ny_texte <- as.vector(ny)
iterator <- itoken(ny_texte,
preprocessor=tolower,
tokenizer=word_tokenizer,
progressbar=FALSE)
vocabulary <- create_vocabulary(iterator)
我.csv是《纽约时报》的文章。 我想在词汇中组合"纽约","南非","埃利斯岛"等词,而不仅仅是像这样的标记:"新","约克"等
我该怎么做?
谢谢
为了更精确:我正在使用这些库
library(text2vec)
library(stopwords)
library(tm)
library(dplyr)
library(readr)
- 例如关于我的结果
ny[1]
1 " LEAD州长科莫与可能的总统竞选等待翅膀宣誓办公室新年前夜第二任纽约首席执行官LEAD州长科莫与可能的总统竞选等待翅膀...
vocabulary
在此处输入图像描述
回答你的问题仍然有点困难:我们无法运行你的代码,因为我们没有"nyt.csv"。但似乎gsub()
会做你想做的事:
ny <- read.csv2("nyt.csv", sep = "t", header = TRUE)
ny <– gsub("new york", "newyork", ny, ignore.case = TRUE)
ny <– gsub("south africa", "southafrica", ny, ignore.case = TRUE)
ny_texte <- as.vector(ny)
(然后运行示例中的itoken()
和create_vocabulary()
命令。