如何把R中XBRL包中的xbrlDoAll创建的列表组织成Excel可读的数据框? [英] How to take the lists created by xbrlDoAll in the XBRL package in R, and organize them into dataframes readable in Excel?
问题描述
使用pdf指南中的示例很简单,但它打印出奇怪的,我不知道如何得到这个到一个适当的数据框架:
##设置stringsAsFactors = FALSE强烈建议使用
##来避免数据帧从字符向量创建因子。
options(stringsAsFactors = FALSE)
##加载库
库(XBRL)
##要分析的XBRL实例文件,直接从SEC存取
##网站:
inst< - http://www.sec.gov/Archives/edgar/data/21344/000002134413000050/ko-20130927.xml
##等级1:完成所有功能工作并返回
##提取信息的数据帧列表:
##不运行:
xbrl.vars< -xbrlDoAll(inst,verbose = TRUE)
这个总结给出了一串不同行长度的列表:
< blockquote>
summary(xbrl.vars)
长度类模式
元素7 data.frame列表
角色5 data.frame列表
计算11数据。帧列表
上下文13数据帧列表
单元4数据帧列表
事实7数据帧列表
脚注5 data.frame列表
defi nition 11 data.frame list
label 5 data.frame list
presentation 11 data.frame list
可能是如此简单,因为我不理解列表的数据框架(列表列表?如果是这样,我为一个愚蠢的问题道歉(这可能是愚蠢的其他原因)。我试图在这个问题的答案底部使用解决方案:在R中与data.frame长度不同的列表列表。所以:
xbrl.vars2< -as.data.frame(as.matrix(xbrl.vars))
这对我来说是愚蠢的,因为当行数不同时,R如何构成一个矩阵?它似乎使R冻结。
感谢您的任何帮助。
XBRL实体 xbrlDoAll
的结果是数据框的列表。有一种方法可以从那里获得财务报表,但不像预期的那样直接。数据框架(事实,上下文,元素,演示文稿,角色等)对应于
$ b XBRL包方便地将XML,XLinks和模式转换为data.frames中明显的关系,所以这个任务相当简单 - 特别是使用像 dplyr 和 tidyr 。请参阅 github 上的资产负债表示例与实体关系图和R代码。
I've been experimenting with the XBRL package in R to try to write a function that would cycle through companies and output financial statements, ideally in a very standard dataframe. But, I don't understand the output. Using the function and then viewing the data frame, all that appears is a running total on the leftmost column, with right-justified URL's of various XML/XBRL/C++ components on the right. I admit I have very little XBRL knowledge, but I must be missing something. How would I use the functions of this package to cycle through and log all XBRL statements, formatting into something usable for an end-user?
Using the example from the pdf guide is easy, but it prints out strangely and I have no idea how to get this into a proper data frame:
## Setting stringsAsFactors = FALSE is highly recommended
## to avoid data frames to create factors from character vectors.
options(stringsAsFactors = FALSE)
## Load the library
library(XBRL)
## XBRL instance file to be analyzed, accessed
## directly from SEC website:
inst <- "http://www.sec.gov/Archives/edgar/data/21344/000002134413000050/ko-20130927.xml"
## Level 1: Function that does all work and returns
## a list of data frames with extracted information:
## Not run:
xbrl.vars <- xbrlDoAll(inst, verbose=TRUE)
Summary of this gives a bunch of lists of differing row lengths:
summary(xbrl.vars) Length Class Mode element 7 data.frame list role 5 data.frame list calculation 11 data.frame list context 13 data.frame list unit 4 data.frame list fact 7 data.frame list footnote 5 data.frame list definition 11 data.frame list label 5 data.frame list presentation 11 data.frame list
This may be so simple as me not understanding a data.frame of lists (list of lists? list of data.frames?) in R. If so, I apologize for a stupid question (it could be stupid for other reasons). I tried to use the solution at the bottom of the answers to this question: list of lists with different lengths to data.frame in R. So: xbrl.vars2<-as.data.frame(as.matrix(xbrl.vars)) Which was dumb of me, because how can R make a matrix when the # of rows are different? It seemed to make R freeze.
Thank you for any help.
The result of xbrlDoAll
is a list of data frames. There is a way to get the financial statements from there, but not as direct as was expected.
The data frames (fact, context, element, presentation, role, etc.) correspond to XBRL entities. To get the data in the financial statement structure, some manipulation is required.
XBRL package conveniently converts XMLs, XLinks and schemas in data.frames with obvious relations, so the task is fairly easy - especially with tools like dplyr and tidyr. See balance sheet example with entity diagram and R code on github.
这篇关于如何把R中XBRL包中的xbrlDoAll创建的列表组织成Excel可读的数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!