Q:

Time difference between rows of data. Is there a faster way to do this than a for loop?

I have a lot of data where every row has a time stamp. I want to make a vector with the time difference between rows. Here is a dummy time sequence:
start.day <- as.POSIXct("2010-11-25 04:13:00 WET")
end.day <- as.POSIXct("2016-11-25 16:25:35 WET")
days.seq <- seq.POSIXt(start.day,end.day,'mins')
days.seq <- sample(days.seq,100000)
days.seq <- days.seq[order(days.seq)]

I started with a for loop but it takes ages for the loop to do the calculations:
start.time <- Sys.time()

time.diff <- NULL
for (i in 2:length(days.seq)) {
  time.diff[i]<- difftime(days.seq[i],days.seq[i-1],units = 'mins')
}
time.diff[1] <- 0
time.diff

end.time <- Sys.time()

difftime(end.time,start.time,'secs')

How can I make R do this faster?

A:

After a quick research on stackoverflow I found that converting the data into a list and using do.call (as suggested in an answer to a related question) was much faster
start.time.A <- Sys.time()
L <- list(days.seq)
LS <- do.call(diff,L)
attributes(LS) <- NULL
LS <- rbind(0,as.data.frame(LS))
str(LS)
start.time.B <- Sys.time()
difftime(start.time.B,start.time.A,'secs')

