我为循环制作了这些,但由于我的数据大小,它们需要很长时间才能运行。反正有没有重写我的for循环,它做同样的事情,但花费更少的时间
for (i in 1:length(dataSL_desktop$usid)) {
usID <- dataSL_desktop$usid[i]
dates <- seq(as.Date(dataSL_desktop$endTimeStamp[i])-30, by = "day", length = 30)
x <- rep(0,30)
for (k in 1:length(datadesktop$Date)) {
for (j in 1:length(dates)) {
if (datadesktop$usID[k] == usID & dates[j] == datadesktop$Date[k] ) {
x[j] <- datadesktop$Visits[k]
}
}
}
}