Question: How can I fix the first value of a column and getting the consecutive difftime of it?

```
 df<- data.frame(Date = c("2012-07-13 15:01:32", "2012-07-05 18:26:31", "2012-07-14 20:23:21"), value=1:3) 

    time=NULL
    for(i in 2:nrow(df)) {
      x<-as.numeric(difftime(df[1,"Date"], df[i,"Date"], units = "hours"))
      time<-rbind(time, x)
    }

```

I tried this and it works but I need the first value of time as NA otherwise I have one value less than needed to bind it with the original df.

And maybe there is a more elegant code than this.

Answer: 
`difftime` is vectorized. You just go ahead and use it the way it is:

```
c(NA, difftime(df[1,1],df[-1,1],units = "hours"))
[1]1 NA 188.58361 -29.36361

```
You can modify your code to,

```
time <- NA
for(i in 2:nrow(df)) {
  x<-as.numeric(difftime(df[1,"Date"], df[i,"Date"], units = "hours"))
  time<-c(time, x)
} 
df$Time <- time

```

I hope this helps!