如何让我的for循环在R中运行得更快?

时间:2015-12-17 04:27:42

标签: r for-loop

我为循环制作了这些,但由于我的数据大小,它们需要很长时间才能运行。反正有没有重写我的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]
      }
    }
  }
}

0 个答案:

没有答案