[R] Date calculation

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jun 9 15:47:12 CEST 2006


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 at 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 at 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
>



More information about the R-help mailing list