【发布时间】:2016-07-27 08:53:02
【问题描述】:
我正在尝试使用以下命令读取位于 here 的数据的 YAML 文件格式,但两者都没有像位于 here 的 CSV 文件那样以所需的输出格式提供数据。 YAML文件中的数据描述为here或很快,可以直接参考最后给出的格式。
我尝试使用这些命令加载数据,但没有成功。谁能指导我将 YAML 文件中的数据正确加载为 R 数据名或按照上面指定的输出格式转换为 csv?
cric <- yaml.load_file("911047.yaml")
cric <- data.frame(yaml.load_file("211028.yaml"))
我正在为您提供以下数据的高级格式供您快速参考(抱歉,在此处粘贴时原始 YAML 代码格式已消失,我无法找到按原样粘贴和重新格式化的方法):
meta:
data_version: 0.6
created: 2013-02-22
revision: 1
info:
city: Southampton
dates:
- 2005-06-13
match_type: T20
outcome:
by:
runs: 100
winner: England
overs: 20
player_of_match:
- KP Pietersen
teams:
- England
- Australia
toss:
decision: bat
winner: England
umpires:
- NJ Llong
- JW Lloyds
venue: The Rose Bowl innings:
- 1st innings:
team: England
deliveries:
- 0.1:
batsman: ME Trescothick
bowler: B Lee
non_striker: GO Jones
runs:
batsman: 0
extras: 0
total: 0
【问题讨论】:
-
您将无法快速将其转换为 data.frame,因为数据没有自然的矩形结构。您将不得不编写一个自定义解析函数将其转换为向量,然后将结果放在一起
rbind()。
标签: r csv dataframe yaml export-to-csv