我已经检查了一堆答案,但我仍然遇到麻烦。字符串变量在R:错误:无法打开文件
我有几十个表和矩阵分配,所以我想实现它在一个自动化的方式。但是当我运行这段代码时,我遇到了错误。
a <- paste("wiot_table_",substr(as.character(year),3,4),sep="")
assign(a,read.csv("/Users/Dreamland/Desktop/Replication_JEP/WIOD\ database\ 1995-2011/2009/wiot2009.csv",header=F,
colClass=c(rep("character",2),rep("num.with.commas",1641))))
mat <- paste("matrix_",substr(as.character(year),3,4),sep="")
eval(parse(paste(mat,"<-as.matrix(",a,"[1:1400,3:1402])",sep="")))
误差
In file(filename, "r") :
cannot open file 'matrix_09<-as.matrix(wiot_table_09[1:1400,3:1402])': No such file or directory
我已经检查paste(mat,"<-as.matrix(",a,"[1:1400,3:1402])",sep="")
和wiot_table_09
和他们都有如我预期值,分别是
"matrix_09<-as.matrix(wiot_table_09[1:1400,3:1402])"
和数据帧。
由于我的工作很复杂,我不能再在这里使用assign
了。这里的任何想法?
非常感谢。
哦,男人,这绝不会发生在我身上,非常感谢! –