gpt4 book ai didi

xml - 在 R 中将 XML 数据转换为平面文件

转载 作者:数据小太阳 更新时间:2023-10-29 02:19:42 26 4
gpt4 key购买 nike

我正在处理一些 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

最佳答案

简单的例子:

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>

关于xml - 在 R 中将 XML 数据转换为平面文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8376900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com