开发者

How to put the results from R into an XML file

开发者 https://www.devze.com 2023-01-08 12:52 出处:网络
In a 开发者_如何学JAVAprevious questionI asked about reading in an XML file into R and carry out basic statistical analysis such as finding the mean and the standard deviation etc. This question is ab

In a 开发者_如何学JAVAprevious question I asked about reading in an XML file into R and carry out basic statistical analysis such as finding the mean and the standard deviation etc. This question is about the reverse of the reading of the original XML file and creating a new XML file that contains the original data and the results from the statistical analysis carried out in R. Is it possible to do this?


Just use the XML package. E.g.:

library(XML)
# from the package documentation:
b = newXMLNode("bob")
saveXML(b)
f = tempfile()
saveXML(b, f)
doc = xmlInternalTreeParse(f)
saveXML(doc)
con <- xmlOutputDOM()
con$addTag("author", "Duncan Temple Lang")
con$addTag("address", close=FALSE)
con$addTag("office", "2C-259")
con$addTag("street", "Mountain Avenue.")
con$addTag("phone", close=FALSE)
con$addTag("area", "908", attrs=c(state="NJ"))
con$addTag("number", "582-3217")
con$closeTag() # phone
con$closeTag() # address
saveXML(con$value(), file="out.xml")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号