用于colnames无效的eval(parse())

时间:2018-04-12 18:49:15

标签: r parsing eval

我正在表演:

for(i in c(1:4)){
colnames(eval(parse(text = paste0("tabDummy",i)))) <- c("RM", "IVS", "COR", "ANO")
}

但是R返回以下错误消息:

Error in colnames(eval(parse(text = paste0("tabDummy", i)))) <- c("RM",  : 
target of assignment expands to non-language object

1 个答案:

答案 0 :(得分:1)

可能是这样的:

df是您的数据框

y = c("RM", "IVS", "COR", "ANO")
for( x in 1:4 ){
  colnames(df)[ colnames(df) == paste0("tabDummy", x) ] <- y[x]
}