【问题标题】:Convert XML Data to Flat File in R在 R 中将 XML 数据转换为平面文件
【发布时间】:2011-12-04 16:55:14
【问题描述】:

我正在处理一些需要转换为平面文件的 XML 数据,以便进行统计分析。我正在使用 R 分析数据。以下是数据样本的样子:

<production xmlns="" diffgr:id="production1130" msdata:rowOrder="1129">
  <ENTITY_ID>116484210</ENTITY_ID>
  <LIQ>0</LIQ>
  <GAS>163</GAS>
  <WTR>0</WTR>
  <WCNT>1</WCNT>
  <DAYS>0</DAYS>
</production>
<production xmlns="" diffgr:id="production1131" msdata:rowOrder="1130">
  <ENTITY_ID>116484210</ENTITY_ID>
  <LIQ>12</LIQ>
  <GAS>130</GAS>
  <WTR>0</WTR>
  <WCNT>1</WCNT>
  <DAYS>0</DAYS>
</production>

我希望将其转换为如下所示的平面文件:

PRODUCTION_ID、ENTITY_ID、LIQ、GAS、WTR、WCNT、DAYS

有什么建议吗?

谢谢,Z

【问题讨论】:

  • 嗯,XML 包将是显而易见的起点。

标签: xml r soap statistics regression


【解决方案1】:

简单示例:

install.packages("XML")
library("XML")
doc = xmlInternalTreeParse("/Users/ras/test.xml") # your path goes here
myframe = xmlToDataFrame(doc)
myframe

产量:

  ENTITY_ID LIQ GAS WTR WCNT DAYS
1 116484210   0 163   0    1    0
2 116484210  12 130   0    1    0

test.xml 是:

<stuff>
    <production xmlns="" diffgr:id="production1130" msdata:rowOrder="1129">
      <ENTITY_ID>116484210</ENTITY_ID>
      <LIQ>0</LIQ>
      <GAS>163</GAS>
      <WTR>0</WTR>
      <WCNT>1</WCNT>
      <DAYS>0</DAYS>
    </production>
    <production xmlns="" diffgr:id="production1131" msdata:rowOrder="1130">
      <ENTITY_ID>116484210</ENTITY_ID>
      <LIQ>12</LIQ>
      <GAS>130</GAS>
      <WTR>0</WTR>
      <WCNT>1</WCNT>
      <DAYS>0</DAYS>
    </production>
</stuff>

【讨论】:

  • 酷,如果您按下帖子旁边的复选标记,我会很高兴,这意味着您接受问题的解决方案:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 2012-09-08
  • 2011-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多