Re: [R] Date calculation

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 09 Jun 2006 - 23:47:12 EST

Try this:

Lines <- "5/2/2006      36560
 5/3/2006     36538
 5/4/2006     36452
 5/5/2006     36510
 5/8/2006     36485
 5/9/2006     36502
 5/10/2006     36584

 5/11/2006 36571"

DF <- read.table(textConnection(Lines), as.is = TRUE) fmt <- "%m/%d/%Y"
DF[,1] <- as.Date(DF[,1], fmt)
date <- as.Date("5/10/2006", fmt)
which.max(DF[,1] > date)

On 6/9/06, stat stat <stat700004@yahoo.co.in> wrote:
> Dear all R users,
>
> Suppose I have a data frame "data" like this:
>
> 5/2/2006 36560
> 5/3/2006 36538
> 5/4/2006 36452
> 5/5/2006 36510
> 5/8/2006 36485
> 5/9/2006 36502
> 5/10/2006 36584
> 5/11/2006 36571
>
> Now I want to create a for loop like this:
>
> date = "5/10/2006"
> for (i in 1: 8)
> {
> if (data[i,1] > date) break
> }
>
> But I get error while executing this. Can anyone tell me the right way to do this?
>
> Sincerely yours
> stat
>
> Send instant messages to your online friends http://in.messenger.yahoo.com
>
> Stay connected with your friends even when away from PC. Link: http://in.mobile.yahoo.com/new/messenger/
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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 Sat Jun 10 00:02:54 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 11 Jun 2006 - 05:34:52 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.