我有以下代码:
final_results <- list()
myfunc <- function(v1) {
deparse(substitute(v1))
}
for (i in mylist) {
...calculations...
tmp_results <- as.data.frame(cbind(effcrs,weights))
colnames(tmp_results) <- c('efficiency',names(inputs),
names(outputs)) # header
rownames(tmp_results) <- namesDMU[,1]
#Save to list
name_in_list <- myfunc(i)
dea_results[[name_in_list]] <- tmp_results
}上面的代码循环遍历数据帧列表。我希望循环产生的每个结果都存储在一个单独的列表中,该列表与从mylist或i获得的原始文件同名
我试过使用deparse substitute。当我将它应用于mylist中的单个项目时,它看起来如下所示:
myfunc(standard_DEA$'2010-11-11')
[1] "standard_DEA$\"2010-11-11\""我不知道问题出在哪里。此时,它以"i“的名称保存所有内容,并替换所有向量,因此最终结果是一个1的列表。
提前谢谢你
发布于 2015-10-06 05:08:07
这看起来像是你想要一个do循环。
library(dplyr)
function_which_returns_dataframe = function(i) {
...calculations...
tmp_results <- as.data.frame(cbind(effcrs,weights))
colnames(tmp_results) <- c('efficiency',names(inputs),
names(outputs)) # header
rownames(tmp_results) <- namesDMU[,1]
tmp_results
}
data_frame(mylist = mylist,
name = names(mylist)) %>%
group_by(mylist, name) %>%
do(function_which_returns_dataframe(.$mylist[[1]]))https://stackoverflow.com/questions/32957468
复制相似问题