2014-09-03 73 views
-1

嗨,我有5個html源,我想在其中運行readHTMLTable並存儲結果。我可以做到這一點單獨使用:R中的readHTMLTable在循環中拋出警告

readHTMLTable(iso.content[1],which=6) 
readHTMLTable(iso.content[2],which=6) 
. 
. 

但是把這個變成一個for循環,當我得到:

library(XML) 
> iso.table<-NULL 
> for (i in 1:nrow(gene.iso)) { 
+ iso.table[i]<-readHTMLTable(iso.content[i],which=6) 
+ } 
Warning messages: 
1: In iso.table[i] <- readHTMLTable(iso.content[i], which = 6) : 
    number of items to replace is not a multiple of replacement length 
2: In iso.table[i] <- readHTMLTable(iso.content[i], which = 6) : 
    number of items to replace is not a multiple of replacement length 
3: In iso.table[i] <- readHTMLTable(iso.content[i], which = 6) : 
    number of items to replace is not a multiple of replacement length 
4: In iso.table[i] <- readHTMLTable(iso.content[i], which = 6) : 
    number of items to replace is not a multiple of replacement length 
5: In iso.table[i] <- readHTMLTable(iso.content[i], which = 6) : 
    number of items to replace is not a multiple of replacement length 

所以我可以單獨做到這一點,但不使用for循環。我不打算用下一次迭代替換當前的數據,所以我不確定警告爲什麼會這樣。

有什麼想法?

回答

2

該錯誤與readHTMLTable確實無關;這全是關於iso.table。我不確定你想要什麼類型的對象,但是如果你想存儲一堆數據。你需要一個列表。而當您將對象分配給列表時,您希望將它們放在[[ ]]而不是[ ]。嘗試

iso.table <- list() 
for (i in 1:nrow(gene.iso)) { 
    iso.table[[i]] <- readHTMLTable(iso.content[i],which=6) 
} 
+0

感謝[[]]提示。 – brucezepplin 2014-09-04 08:06:34