R “多语言中未列出”失败;列表“;

R “多语言中未列出”失败;列表“;,r,list,character,R,List,Character,在这些日子里,我从文档中构建了一个关键字列表: txtdir<-"E:/2015Ddtrial" txtnames<-list.files(txtdir, pattern = ".txt", all.files = FALSE, recursive = TRUE, include.dirs = FALSE, full.names=TRUE) # prepared for data input pkw<-vector() #extract

在这些日子里,我从文档中构建了一个关键字列表:

txtdir<-"E:/2015Ddtrial"
txtnames<-list.files(txtdir, pattern = ".txt", all.files = FALSE,
                     recursive = TRUE, include.dirs = FALSE, full.names=TRUE)
# prepared for data input
pkw<-vector()
#extract the keywords of the papers in the text files
for(i in 1:length(txtnames)) {
  fc<-file(txtnames[i], open = "r", encoding = "UTF-8")
  #alternative method of reading files: txtls<-readLines(con = fc, n=6, encoding = "unknown", skipNul = TRUE)
  txtls<-scan(file = fc, what=character(), nmax = 6, sep = "\n", blank.lines.skip = TRUE, skipNul = TRUE, fileEncoding = "UTF-8")
  rawvec<-grep("关键词", txtls, value = TRUE)
  first<-regexpr("关键词", rawvec, ignore.case = FALSE)
  last<-regexpr("分类号", rawvec, ignore.case = FALSE)
  pkw<-append(pkw, substring(rawvec, first+4, last-2))
  close(fc)
}
#combine all vectors into one line
kwdict<-gsub("^[[:blank:]+]|[[:blank:]+]$", "", pkw)
我试着用“unlist”把它们分解成单词

expansion <- unlist(kwdict, recursive = FALSE)

扩展请将
dput(kwdict)
的输出添加到您的帖子中。我不确定您的变量是否是
列表
。尝试
类(变量名称)
。可能
扫描(text=kwdict,what=“”)
?可能重复,谢谢您的建议,我检查了这个参数,“kwdict”类命名为“character”!!!我用“scan”、“regexpr”和“append”来构建它,怎么可能呢?!但是,这个伪列表是否有任何方法可以将其分隔为单个单词?
expansion <- unlist(kwdict, recursive = FALSE)