尝试使用以下代码创建一个足够好的战利品:
dateList = c("2016-01-08","2016-01-09","2016-01-10","2016-01-11",
"2016-01-12")
df1 <- get_intraday_data(cookie, what="heart-rate", date=dateList[1])
df2 <- get_intraday_data(cookie, what="heart-rate", date=dateList[2])
df3 <- get_intraday_data(cookie, what="heart-rate", date=dateList[3])
df4 <- get_intraday_data(cookie, what="heart-rate", date=dateList[4])
df5 <- get_intraday_data(cookie, what="heart-rate", date=dateList[5])
我已经编写了下面的循环,它基本上在循环中用[i]代替1-5,但它只生成一个名为i的整数。我怎样才能将每一天都作为自己的数据框?
for (i in 1:5){
df[i] <- get_intraday_data(cookie, what="heart-rate", date=dateList[i])
}
由于
答案 0 :(得分:0)
您可以尝试map
包中的purrr
功能。它有点像lapply。我不确定我是否做得对,但也许这样可行:
purrr::map(1:5, ~ get_intraday_data(cookie, what="heart-rate", date=dateList[.x]))
答案 1 :(得分:0)
在for循环中使用“assign”函数:
dateList = c("2016-01-08","2016-01-09","2016-01-10","2016-01-11",
"2016-01-12")
for (i in 1:length(dateList)) {
assign(paste0("df", i), get_intraday_data(cookie, what="heart-rate", date=dateList[i]))
}