我正在尝试导入R资产负债表的Excel电子表格,我试图将其导入,以便它看起来或多或少像现在的资产负债表。
Assets 2011, 2010, 2009
Non current assets 32.322 3.111
intangible assets 12,222
沿着这些方向的东西。我也试图导入第二个标签,这也是一个不同的资产负债表。我的想法是,我可能有50个或更多的资产负债表。这对分析来说效率低吗?
我只对每个资产负债表中的一些相同变量感兴趣(想想,流动资产,所有年份的非流动资产等)是否可以从excel spead导入特定的行和列片
例如,只需导入;
A) Non current assets 32.322 3.111 322
B) Current assets 345 543 2.233
等? - 行名称不会更改,所以我可以使用函数来执行此操作吗?
答案 0 :(得分:1)
看看quantmod !!
library(quantmod)
library(xlsx)
getFin("GS")
gs_BS <- GS.f$BS$A
str(gs_BS)
#num [1:42, 1:4] 106533 NA 113003 71883 NA ...
#- attr(*, "dimnames")=List of 2
# ..$ : chr [1:42] "Cash & Equivalents" "Short Term Investments" "Cash and Short Term Investments" "Accounts Receivable - Trade, Net" ...
# ..$ : chr [1:4] "2015-12-31" "2014-12-31" "2013-12-31" "2012-12-31"
#- attr(*, "col_desc")= chr [1:4] "As of 2015-12-31" "As of 2014-12-31" "As of 2013-12-31" "As of 2012-12-31"
transposed <- t(gs_BS)
write.xlsx(transposed, "C:\\Users\\your_path_here\\Desktop\\bal_sheet.xlsx", row.names=FALSE)
transp <- read.xlsx("C:\\Users\\your_path_here\\Desktop\\bal_sheet.xlsx" , sheetName="Sheet1")
transp$year <- c("2015","2014","2013","2012")")
这也很好。
require(quantmod)
equityList <- read.csv("EquityList.csv", header = FALSE, stringsAsFactors = FALSE)
names(equityList) <- c ("Ticker")
for (i in 1 : length(equityList$Ticker)) {
temp<-getFinancials(equityList$Ticker[i],src="google",auto.assign=FALSE)
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Income_Statement(Annual).csv",sep=""))
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Balance_Sheet(Annual).csv",sep=""))
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Cash_Flow(Annual).csv",sep=""))
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Income_Statement(Quarterly).csv",sep=""))
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Balance_Sheet(Quaterly).csv",sep=""))
write.csv(temp$IS$A,paste(equityList$Ticker[i],"_Cash_Flow(Quaterly).csv",sep=""))
}
另外,请检查一下。
https://msperlin.github.io/pafdR/importingInternet.html
还有其他方法可以做很相似的事情。如果您需要更多帮助,请回复。