Re: [R] Finding the last value before a certain date

2012-07-19 Thread William Dunlap
tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Rui Barradas > Sent: Thursday, July 19, 2012 1:11 AM > To: Robert Latest > Cc: r-help@r-project.org > Subject: Re: [R] Finding the last value b

Re: [R] Finding the last value before a certain date

2012-07-19 Thread Rainer Schuermann
---- Original-Nachricht ---- > Datum: Thu, 19 Jul 2012 09:42:05 +0200 > Von: Robert Latest > An: > Betreff: [R] Finding the last value before a certain date > Hello all, > > I have a dataframe that looks like this: > > head(df) > datey > 1

Re: [R] Finding the last value before a certain date

2012-07-19 Thread Eik Vettorazzi
Hi Robert, how about this (assuming your data.frame is ordered by date): tmp<-read.table(textConnection("datey 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 Hello

Re: [R] Finding the last value before a certain date

2012-07-19 Thread Rui Barradas
Hello, Try the following. dat <- read.table(text=" datey 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=TRUE, stringsAsFactors=FALSE) dat$date <- as.Date(dat$date) str(dat) search <- as.Date("2010-10-06") max(wh

[R] Finding the last value before a certain date

2012-07-19 Thread Robert Latest
Hello all, I have a dataframe that looks like this: head(df) datey 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 I need a function that, given any date, returns the y value corresponding to the given date or the last day b