1
我有一個xml文件的問題。我無法從這些xml結構中獲得正確的數據幀。將xml轉換爲沒有NA的數據幀
<Node1 Value1="start">
<Node2 Value2="1110" Value3="345">
<Node3 Value4="500" Value5="3">
<Node4 Value6="484663" Value7="130" />
<Node4 Value6="253234" Value7="59" />
<Node4 Value6="198476" Value7="131" />
</Node3>
<Node3 Value4="113" Value5="1">
<Node4 Value6="2009343" Value7="555" />
<Node4 Value6="2530931" Value7="333" />
<Node4 Value6="1984761" Value7="111" />
</Node3>
</Node2>
</Node1>
我用下面幾行來獲取數據幀。但是有很多NA。我如何強制data.table重複值,而不是將NA放入?
library(data.table)
library(XML)
# test.xml = the xml-file
test <- xmlTreeParse("test.xml", useInternalNodes=TRUE)
Node1 <- rbindlist(lapply(test["//*"], function(x)as.list(xmlAttrs(x))), fill = TRUE, use.names = TRUE)
結果應該是這樣..
Value1 Value2 Value3 Value4 Value5 Value6 Value7
start 1110 345 500 3 484663 130
start 1110 345 500 3 253234 59
start 1110 345 500 3 198476 131
start 1110 345 113 1 2009343 555
start 1110 345 113 1 2530931 333
start 1110 345 113 1 1984761 111
需要使用一個新的例子。 – Christian