これはまだ質問されていないと思いますが、複数のレベルと不均一な構造を持つリストの情報を「長い」形式のデータフレームに結合する方法はありますか?
具体的には:
library(XML)
library(plyr)
xml.inning <- "http://gd2.mlb.com/components/game/mlb/year_2009/month_05/day_02/gid_2009_05_02_chamlb_texmlb_1/inning/inning_5.xml"
xml.parse <- xmlInternalTreeParse(xml.inning)
xml.list <- xmlToList(xml.parse)
## $top$atbat
## $top$atbat$pitch
## des id type x y
## "Ball" "310" "B" "70.39" "125.20"
構造は次のとおりです。
> llply(xml.list, function(x) llply(x, function(x) table(names(x))))
$top
$top$atbat
.attrs pitch
1 4
$top$atbat
.attrs pitch
1 4
$top$atbat
.attrs pitch
1 5
$bottom
$bottom$action
b des event o pitch player s
1 1 1 1 1 1 1
$bottom$atbat
.attrs pitch
1 5
$bottom$atbat
.attrs pitch
1 5
$bottom$atbat
.attrs pitch runner
1 5 1
$bottom$atbat
.attrs pitch runner
1 7 1
$.attrs
$.attrs$num
character(0)
$.attrs$away_team
character(0)
$.attrs$
私が持ちたいのは、適切な ( top、atbat、bottom )とともに、ピッチカテゴリの名前付きベクトルからのデータ フレームです。したがって、列の数が異なるために data.frame に収まらないレベルを無視する必要があります。このようなもの:
first second third des x
1 top atbat pitch Ball 70.29
2 top atbat pitch Strike 69.24
3 bottom atbat pitch Out 67.22
これを行うエレガントな方法はありますか?ありがとう!