xml到r数据提取 [英] xml to r data extraction
本文介绍了xml到r数据提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 xml 文件中提取数据并绘制以下图表:深度与时间戳.标题应该是 IFC 代码.我尝试使用 xmlToList 和 xmlTodataframe,但我没有这样做.我需要帮助.我的 xml 文件看起来像
I need to extract data from xml file and plot graphs of: depth vs timestamp. Heading should be the IFC code. I tried using xmlToList and xmlTodataframe, but I failed doing so. I need help. My xml file looks like
<document>
<site>
<IFC_code>HONEYCR01</IFC_code>
<Latitude>41.960161</Latitude>
<Longitude>-90.470759</Longitude>
<River>Honey Creek</River>
<Road>Hwy 136, 1st Street</Road>
<Town>Charlotte</Town>
<from_sensor_to_river_bottom>9.35</from_sensor_to_river_bottom>
<Unit>foot</Unit>
</site>
<data>
<value>
<timestamp>2012-05-17 15:30:03-05</timestamp>
<depth>8.53</depth>
</value>
<value>
<timestamp>2012-05-17 14:30:06-05</timestamp>
<depth>8.50</depth>
</value>
<value>
<timestamp>2012-05-17 14:15:02-05</timestamp>
<depth>8.51</depth>
</value>
<value>
<timestamp>2012-05-17 14:00:12-05</timestamp>
<depth>8.50</depth>
</value>
<value>
<timestamp>2012-05-17 13:45:08-05</timestamp>
<depth>8.51</depth>
</value>
</data>
</document>
推荐答案
好像有效:
library(XML)
doc <- xmlParse("a.xml")
xmlToDataFrame(
getNodeSet(doc, "//value"),
colClasses=c("character","numeric")
)
这篇关于xml到r数据提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文