Skip to content

midpoint between two dates

1 message · Pete Brecknock

#
eric wrote
How about ...

date1 = as.Date(c("2013-10-10","2013-11-15","2013-12-25"))
date2 = as.Date(c("2013-10-20","2013-11-20","2013-12-30"))

df <- data.frame(id=c(1,2,3),date1,date2)
df$mid <- df$date1 + floor((df$date2-df$date1)/2)

print(df)

  id      date1      date2        mid
1  1 2013-10-10 2013-10-20 2013-10-15
2  2 2013-11-15 2013-11-20 2013-11-17
3  3 2013-12-25 2013-12-30 2013-12-27


HTH

Pete

 



--
View this message in context: http://r.789695.n4.nabble.com/midpoint-between-two-dates-tp4680649p4680654.html
Sent from the R help mailing list archive at Nabble.com.