1

I am reading HTML tables, and can do that fine, but I am collecting tables from multiple years. Unfortunately, the columns and rows are different in each year, so I wanted to add them all recursively to a list, so I can later apply lapply and do some analysis.

I can download the table and manipulate it into a dataframe when I do it once, but then when I add it to a list, the list only accepts the first column.

library(XML)
#reg
r=readHTMLTable('http://www.nhl.com/stats/team?season=20132014&gameType=2&viewName=summary#',stringsAsFactors=FALSE)
r=as.data.frame(r[3])
for(i in 3:ncol(r)){
    r[,i]=as.numeric(r[,i])
}

This gives me r as something I can manipulate. I want to add it to a list:

> l=as.list(NULL)
> l[1]=r
Warning message:
In l[1] = r :
  number of items to replace is not a multiple of replacement length
> l
[[1]]
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"

Does anyone know how I can add it into my list so I keep the dimensions

> dim(r)
[1] 30 25

The issue is, I have many other tables that I would like to add, and was able to add them, but each one that was added only included the first column/element.

Any ideas is greatly appreciated

Thanks!

1 Answer 1

1

A little more research, and I found an answer. I feel guilty about it, but here it is:

l[[1]]=r

adds the table r to the list, and can also be done recursively

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.