Lapply执行变量列表的命令

时间:2016-07-21 10:11:46

标签: r lapply

我打算改变某些因素的等级顺序。 目的是应用此命令

Df$X1 <- ordered(Df$X1, levels = c("5", "4", "3", "2", "1"))

到变量列表(X1到X2)

        Df <- data.frame(
  X1 = ordered(sample(1:5,30,r=T)),
  X2 = ordered(sample(1:5,30,r=T)),
  X3 = as.factor(sample(1:5,30,r=T)),
  Y = as.factor(sample(1:5,30,r=T))
)

tmplistporadove <- as.list(paste("Df$",names(Df)[1:2],sep=""))
zmena <- lapply(tmplistporadove, function(x) substitute(x <- ordered(x, levels = c("5", "4", "3", "2", "1")))   )
eval(zmena)

但是R只打印出这个:

X[[i]] <- ordered(X[[i]], levels = c("5", "4", "3", "2", "1"))

0 个答案:

没有答案