R中的XLConnect是否为writeNamedRegion()进行了矢量化?它的语法是什么?

时间:2015-12-08 21:12:58

标签: vectorization xlconnect

如果可能的话,我想使用来自R的XLConnect使用矢量化在excel工作簿中的多个工作表中写入NamedRegions。

我有一个清单: trya $ GRP1         var1 var2 var3 1455100 459 21 459

$ GRP2        var1 var2 var3 936710 463 20 463

我有一个工作簿模板(wb1),其中包含一个包含namedRegions(每个单元格)的工作表(Sheet1)。 Sheet1中的namedRegions命名为:" varn1"," varn2"," varn3"

我可以克隆Sheet1来创建单独的工作表,以包含trya中每个grp的数据。

cloneSheet(wb1,sheet =" Sheet1",name = names(trya))

但是..如何在这些表格中写入NamedRegions?我很高兴使用3个单独的传递,每个传递一个NamedRegion来写入多个工作表。 这是我开始使用NamedRegion" varn1:使用代码的代码 例如writeNamedRegion(对象,数据,区域名称,标题,rownames)

writeNamedRegion(wb1,trya ???,name =" varn1",header = FALSE)

我不知道 1.如何通常选择trya的元素:trya [[1]] $ var1? 2.如何循环克隆的表格,名为.... names(trya)?

任何帮助将不胜感激。 Jan

1 个答案:

答案 0 :(得分:0)

许多XLConnect的函数/方法都是矢量化的。这也适用于writeNamedRegion。以下示例说明了如何使用单个list调用将data.frame writeNamedRegion require(XLConnect) wb = loadWorkbook("test.xlsx", create = TRUE) mySheets = paste0("MySheet", 1:3) myNames = paste0("MyName", 1:3) myData = list(mtcars, CO2, USArrests) createSheet(wb, name = mySheets) createName(wb, name = myNames, formula = paste(mySheets, "$A$1", sep = "!")) writeNamedRegion(wb, data = myData, name = myNames) saveWorkbook(wb) 写入适当的命名区域:

 $subscriber->custom_fields = array(
            'Top 3 biggest fears related to dating' => '$threefears',
            'How would the person you most admire handle these fears' => '$handlefears',
            'What are 3 actions you can take today to act more like the person you most admire' => '$threeactions',
            'How will taking these actions change your attitude towards dating and your life' => '$changelife',
        );