Re: [R] select previous date

From: Ben Rich <richmcb_at_gmail.com>
Date: Fri 19 Aug 2005 - 02:14:55 EST

You can try this:

dates <- df$date[df$temp==15]
one.month.before <- sapply(strsplit(dates, "-"), function(x) paste(x[1], sprintf("%02d", as.numeric(x[2])-1), x[3], sep="-")) df[df$date %in% one.month.before,]

Ben

On 8/18/05, alessandro carletti <alxmilton@yahoo.it> wrote:
> Hi everybody,
> could anyone help me in finding a way for selecting
> from a dataframe each row that comes before another
> that matches a condition?
>
> EXAMPLE:
> df
> raw.number name date temp
> 1 aaa 2001-04-15 15
> 2 aaa 2001-01-15 12
> 3 aaa 2001-03-15 13
> ...
> i-1 bbb 2002-04-15 15
> i bbb 2002-03-15 14
>
> the condition is:
> df$temp==15
> matching raws are 1 and i-1:
> I need something to select (only) rows where date=one
> month before the matching raws, so raws 3 and i.
> (the variable name has more than one level)
> Thanks
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Aug 19 02:20:29 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:30:20 EST