您好我正在尝试编写一个循环来帮助我使用循环从网站检索数据,但我仍然坚持如何将date
粘贴到URL
上。例如,我正在尝试检索最近5天的数据....
# 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")
答案 0 :(得分:3)
如果我了解您尝试在此处执行的操作,请使用paste
或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")
)