Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将列表从R导出到Excel,同时维护列表名称和子列表名称_R_Excel_List_Quantmod - Fatal编程技术网

将列表从R导出到Excel,同时维护列表名称和子列表名称

将列表从R导出到Excel,同时维护列表名称和子列表名称,r,excel,list,quantmod,R,Excel,List,Quantmod,我正试图从谷歌金融公司获得财务信息,同时使用R的软件包“quantmod”。我在列表中获得了令人满意的结果,但我想将其导出到excel文件。每个列表成员有不同的电子表格,所述表格的名称为列表中的名称。到目前为止,我有以下代码和输出: library(quantmod) library(dplyr) library(tidyr) symbols <- stockSymbols()[,1:2] allfunc<-function(y) sapply(fin1, function(x) x

我正试图从谷歌金融公司获得财务信息,同时使用R的软件包“quantmod”。我在列表中获得了令人满意的结果,但我想将其导出到excel文件。每个列表成员有不同的电子表格,所述表格的名称为列表中的名称。到目前为止,我有以下代码和输出:

library(quantmod)
library(dplyr)
library(tidyr)
symbols <- stockSymbols()[,1:2]
allfunc<-function(y) sapply(fin1, function(x) x$IS$A[y, ],USE.NAMES = TRUE)*10^6
s <- c("AAPL","GOOG","IBM","GS","AMZN","GE")
want<-c("Total Revenue","Operating Income")
fin1 <- lapply(s, getFinancials, auto.assign=FALSE,names=s)
names(fin1)<-s
all<- lapply(want,allfunc)
ss<-sapply(want,allfunc)
names(all)<-want
all
我希望在xlsx中有两张“收入”、“营业收入”,同时保留行名和列名。但是我找不到一种方法来处理列表。 请提供类似以下内容的帮助:

library(xlsx)

wb = createWorkbook()  # Create an Excel workbook object

lapply(names(all), function(s) {
  sht = createSheet(wb, s)        # Add a sheet to the workbook using the name of the list element we want to save
  addDataFrame(all[[s]], sht)     # Add the list element (i.e., the data frame) to the current worksheet
}

saveWorkbook(wb, "my_workbook.xlsx")  # Save the workbook as a Excel file
library(xlsx)

wb = createWorkbook()  # Create an Excel workbook object

lapply(names(all), function(s) {
  sht = createSheet(wb, s)        # Add a sheet to the workbook using the name of the list element we want to save
  addDataFrame(all[[s]], sht)     # Add the list element (i.e., the data frame) to the current worksheet
}

saveWorkbook(wb, "my_workbook.xlsx")  # Save the workbook as a Excel file