【发布时间】:2017-09-13 04:19:48
【问题描述】:
为了节省时间,我想遍历包含月开始日期和月结束日期的向量,每次都发出 API 请求并存储每个请求的输出。
假设我们从一个名为 dateTable 的数据框开始,其中包含日期范围内每月的第一天和最后一天:
firstDOM lastDOM
2016-05-01 2016-05-31
2016-06-01 2016-06-30
2016-07-01 2016-07-31
2016-08-01 2016-08-31
2016-09-01 2016-09-30
2016-10-01 2016-10-31
2016-11-01 2016-11-30
2016-12-01 2016-12-31
2017-01-01 2017-01-31
2017-02-01 2017-02-28
2017-03-01 2017-03-31
2017-04-01 2017-04-30
2017-05-01 2017-05-31
2017-06-01 2017-06-30
2017-07-01 2017-07-31
2017-08-01 2017-08-31
我想遍历每一行并将 startDate 和 endDate 粘贴到以下 rest API 请求中,但是在运行这段代码时我不断收到以下错误,我不确定是什么原因造成的:
for (i in 1:nrow(dateTable)) {
startDate <- dateTable$firstDOM
endDate <- dateTable$lastDOM
#Obtian the Volume of Mentions by Day using declared specs from above
qryMen <- GET(paste("https://newapi.brandwatch.com/projects/", projId, dataSpec
, "?queryId=", queryId, "&startDate=", startDate, "&endDate=", endDate
, '&pageSize=', pageSize, "&access_token=", accessToken$access_token, sep = ""))
}
#Error
Error: length(url) == 1 is not TRUE
任何帮助将不胜感激!
【问题讨论】: