简体   繁体   English

r for循环将列表中的每个文件分配给单个语料库

[英]r for loop to assing every file in a list to an individual corpus

I whant to resume a lot of similar commands into a for loop. 我希望将许多类似的命令恢复到for循环中。

q001<-Corpus(VectorSource(read.table("./q001.txt",encoding="latin1")))
q001<-Corpus(VectorSource(read.table("./q001.txt",encoding="latin1")))
....
q150<-Corpus(VectorSource(read.table("./q150.txt",encoding="latin1")))

I have limited computational resources that´s why I want to build separate corpus, clean and make tdm on each of them and later merge all the final tdm into a single tdm matrix 我的计算资源有限,这就是为什么我要构建单独的语料库,清理它们并对其进行tdm,然后将所有最终tdm合并到一个tdm矩阵中的原因

I build the following loop 我建立以下循环

for(i in bNames){
  filepath <- paste("./Sample/", i,".txt", sep="")
  assign(i, Corpus(VectorSource(read.table(filepath,encoding="latin1")))
}

Where bNames is a list of files to be read as individual corpus 其中bNames是要作为单个语料库读取的文件的列表

And gets an error: 并得到一个错误:

Error: unexpected '}' in:
"  assign(i, Corpus(VectorSource(read.table(filepath,encoding="latin1")))
}"

What I'm doing wrong? 我做错了什么?

您在assign末尾缺少括号

assign(i, Corpus(VectorSource(read.table(filepath,encoding="latin1"))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM