Skip to content
Prev 300552 / 398503 Next

Finding the last value before a certain date

Hi Robert,
how about this (assuming your data.frame is ordered by date):

tmp<-read.table(textConnection("        date    y
1 2010-09-27 1356
2 2010-10-04 1968
3 2010-10-11 2602
4 2010-10-17 3116
5 2010-10-24 3496
6 2010-10-31 3958"),header=T,colClasses=c(date="Date"))
tmp[max(which(tmp$date<as.Date("2010-10-06"))),"y"]

hth.

Am 19.07.2012 09:42, schrieb Robert Latest: