如何把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?

查看:308
本文介绍了如何把R中XBRL包中的xbrlDoAll创建的列表组织成Excel可读的数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用R的XBRL包进行试验,试图编写一个循环公司和输出财务报表的函数,理想情况是在一个非常标准的数据框中。但是,我不明白输出。使用该函数,然后查看数据框,所有出现的数据都是最左边一列的总数,右边是各种XML / XBRL / C ++组件的右对齐URL。我承认我的XBRL知识很少,但我一定会错过一些东西。我如何使用这个包的功能来循环和记录所有的XBRL语句,格式化为最终用户可以使用的东西?

使用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冻结。

感谢您的任何帮助。

解决方案

xbrlDoAll 的结果是数据框的列表。有一种方法可以从那里获得财务报表,但不像预期的那样直接。数据框架(事实,上下文,元素,演示文稿,角色等)对应于

XBRL实体。要获取财务报表结构中的数据,需要进行一些操作。


$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆