dataframe - Assistance Required to append to existing R Data Frame Object -
i trying pull historical price information asx200 list of companies. issue have r data frame using keeps getting overwritten (instead of appended to). final dataframe contains data last asx200 ticker. pls see attempt below:
library(xml) url <- "http://www.asx200list.com" getasx200 <- readhtmltable(url, which=1, header = true) codes <- getasx200$code codes <- lapply(codes, as.character) (i in 1:200) { url2 <- paste("http://ichart.finance.yahoo.com/table.csv?s=", codes[i], ".ax", sep = "") dat <- read.csv(url2) dat$date <- as.date(dat$date, "%y-%m-%d") dat$code <- codes[i] }
collecting list little bit tricky. here's example:
library(xml) url <- "http://www.asx200list.com" getasx200 <- readhtmltable(url, which=1, header = true) codes <- getasx200$code codes <- lapply(codes, as.character) datlist <- list() (i in 1:200) { url2 <- paste("http://ichart.finance.yahoo.com/table.csv?s=", codes[i], ".ax", sep = "") dat <- read.csv(url2) dat$date <- as.date(dat$date, "%y-%m-%d") dat$code <- codes[i] datlist <- c(datlist, list(dat)) } print(head(datlist[[1]]))
Comments
Post a Comment