简体   繁体   English

R中的readHTMLTable在for循环内引发警告

[英]readHTMLTable in R throws warning within for loop

Hi I have 5 html sources, in which I want to run readHTMLTable on each and store the result. 嗨,我有5个html源,我想在每个源上运行readHTMLTable并存储结果。 I can do this individually using: 我可以使用:

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

however when putting this into a for loop I get: 但是,当将其放入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

So I can do this individually, but not using a for loop. 因此,我可以单独执行此操作,但不能使用for循环。 It is not my aim to replace the current data with the next iteration, so I am unsure why the warning presents this. 我的目标不是用下一个迭代替换当前数据,所以我不确定为什么警告会出现这种情况。

any ideas? 有任何想法吗?

The error has nothing to do with readHTMLTable really; 该错误与readHTMLTable无关。 it's all about iso.table . 都是关于iso.table I'm not sure what type of object you wanted that to be, but if you want to store a bunch of data.frames, you're going to need a list. 我不确定您想要的对象类型是什么,但是如果您想存储一堆data.frames,则需要一个列表。 And when you're assigning objects to a list, you want to place them with [[ ]] not [ ] . 当您将对象分配给列表时,您想将其放置为[[ ]]而不是[ ] Try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM