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]]
> testV1 V2 1 5/2/2006 36560 2 5/3/2006 36538 3 5/4/2006 36452 4 5/5/2006 36510 5 5/8/2006 36485 6 5/9/2006 36502 7 5/10/2006 36584 8 5/11/2006 36571 > dates <- strptime(test$V1, "%d/%m/%Y") ------------------------------------------------------------------- Jacques VESLOT CNRS UMR 8090 I.B.L (2?me ?tage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- stat stat a ?crit :> 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 >
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
>