我正在尝试使用lapply来浏览数据帧列表并为每个数据帧执行自定义函数。在函数中,我试图根据数据集的名称命名工作表(使用xlsx)。这可能吗?见例:
myList <- list(DataFrame1, DataFrame2, DataFrame3, DataFrame4)
require(xlsx)
export <- createWorkbook()
lapply(myList,
ExcelExport <- function(dataset) {
nameDF <- deparse(substitute(dataset))
# Use another function and store the output
DF <- as.data.frame(function2(dataset))
# Here is where I'm having trouble naming the worksheet according to the name of the Dataframe:
wksht <- createSheet(wb=export, sheetName = paste("Dataset is ", nameDF, sep = ""))
addDataFrame(x=DF, sheet = wksht)
)
# Save it to an excel file (either existing or new) under a given name
saveWorkbook(export, "Export1.xlsx")
我从Getting the name of a data frame找到了deparse(substitute())
,但是lapply似乎正在将我的数据框重命名为X[[i]]
,然后会为&#39; [&#39;
答案 0 :(得分:0)
这是编辑后的代码,允许您访问列表节点的名称。请在发布前检查您的代码,它包含一些含糊之处。
$locationProvider.html5Mode(true)