R dataframe from XML when values are multiple or missing

前端 未结 4 1260
盖世英雄少女心
盖世英雄少女心 2020-12-16 08:40

This question is similar to a previous question, Import all fields (and subfields) of XML as dataframe, but I want to pull out only a subset of the XML data and want to incl

4条回答
  •  清歌不尽
    2020-12-16 08:50

    You can use xmlToList and then plyr to get a dataframe you can use

    require(XML)
    require(plyr)
    xD <- xmlParse(xData)
    xL <- xmlToList(xD)
    ldply(xL, data.frame)
    > ldply(xL, data.frame)
       .id     name buildings.building.type buildings.building.bname
    1 city   London                landmark             Tower Bridge
    2 city New York                 station            Grand Central
    3 city    Paris                landmark             Eiffel Tower
      buildings.building.type.1 buildings.building.bname.1
    1                   station                   Waterloo
    2                                             
    3                  landmark                     Louvre
    

    You can pick what you need from this dataframe

提交回复
热议问题