2014-09-03 77 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