Question

Hello I am trying to write a loop that will help me retrieve data from a site using a loop, but I am stuck on how to paste the date onto the URL. For example, I am trying to retrieve the last 5 days of data....

# Get Todays Date
Friday <- Sys.Date()

# Get Previous 5 days
Thursday <- Friday - 1
Wednesday <- Thursday -1
Tuesday <- Wednesday -1
Monday <- Tuesday -1

#Make Them "readable" for Site`
Friday <- format(Friday, "%Y%m%d")
Thursday<- format(Thursday, "%Y%m%d")
Wednesday<- format(Wednesday, "%Y%m%d")
Tuesday<- format(Tuesday, "%Y%m%d")
Monday<-format(Monday, "%Y%m%d")

#I would like to set what stock I want to retrieve prior to looping
#What Stock and exchange?
GOOG.O

#Get Data by Date
FRIDAY <- read.delim(header=TRUE, stringsAsFactor=FALSE,"http://hopey.netfonds.no/tradedump.php?date=20140214&paper=GOOG.O&csv_format=txt")
Was it helpful?

Solution

If I understand what you try to do here, just use paste or paste0:

stock.name <- "GOOG.O"

FRIDAY <- read.delim(header=TRUE, stringsAsFactor=FALSE,
            paste0("http://hopey.netfonds.no/tradedump.php?date=", Friday,
                   "&paper=", stock.name,
                   "&csv_format=txt")
          )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top