[R] Date calculation

2006-06-09 Thread stat stat
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/200636571
   
  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


Re: [R] Date calculation

2006-06-09 Thread Jacques VESLOT
  test
  V1V2
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/200636571

   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


Re: [R] Date calculation

2006-06-09 Thread Gabor Grothendieck
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/200636571

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 [EMAIL PROTECTED] 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/200636571

  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


[R] Date Calculation

2004-06-17 Thread Ko-Kang Kevin Wang
Hi,

I've been playing with:
 joinDate - format(strptime(as.vector(forum[,2]), %d-%b-%y),
+%d-%b-%Y)
 today - format(strptime(as.vector(14-Jun-04), %d-%b-%Y),
+ %d-%b-%Y)
 joinDate
 [1] 04-Feb-2004 13-Feb-2004 26-Feb-2004 27-Feb-2004
27-Feb-2004
 [6] 27-Feb-2004 29-Feb-2004 01-Mar-2004 02-Mar-2004
07-Mar-2004
[11] 08-Mar-2004 17-Mar-2004 20-Mar-2004 22-Mar-2004
22-Mar-2004
[16] 23-Mar-2004 23-Mar-2004 24-Mar-2004 01-Apr-2004
01-Apr-2004
[21] 01-Apr-2004 01-Apr-2004 02-Apr-2004 06-Apr-2004
09-Apr-2004
[26] 11-Apr-2004 14-Apr-2004 03-May-2004 04-May-2004
30-May-2004
[31] 01-Jun-2004 10-Jun-2004 14-Jun-2004 17-Jun-2004
17-Jun-2004
 today
[1] 14-Jun-0004
 joinDate - today
Error in joinDate - today : non-numeric argument to binary operator

But it didn't quite work.  What I'd like joinDate - today to return is
the number of days to today, since joinDate.  I'm sure it has been asked
before however a search on r-help didn't found me any relevant
information *_*.

Cheers,

Kevin


Ko-Kang Kevin Wang, MSc(Hon)
SLC Stats Workshops Co-ordinator
The University of Auckland
New Zealand

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Date Calculation

2004-06-17 Thread Martin Maechler
 KKWa == Ko-Kang Kevin Wang [EMAIL PROTECTED]
 on Thu, 17 Jun 2004 19:57:39 +1200 writes:

KKWa Hi,
KKWa I've been playing with:
 joinDate - format(strptime(as.vector(forum[,2]), %d-%b-%y),
KKWa +%d-%b-%Y)
 today - format(strptime(as.vector(14-Jun-04), %d-%b-%Y),
KKWa + %d-%b-%Y)
 joinDate
KKWa [1] 04-Feb-2004 13-Feb-2004 26-Feb-2004 27-Feb-2004
KKWa 27-Feb-2004
KKWa [6] 27-Feb-2004 29-Feb-2004 01-Mar-2004 02-Mar-2004
KKWa 07-Mar-2004
KKWa 
 today
KKWa [1] 14-Jun-0004
 joinDate - today
KKWa Error in joinDate - today : non-numeric argument to binary operator

KKWa But it didn't quite work.  What I'd like joinDate -
KKWa today to return is the number of days to today, since
KKWa joinDate.  I'm sure it has been asked before however a
KKWa search on r-help didn't found me any relevant
KKWa information *_*.

Kevin, 
   [[did you have tough day? usually your Q/A are much better ;-()]]

both joinDate and today are results of format() and hence
character vectors (with no time information left).  
You didn't really expect  - to work with characters?

OTOH,  - properly does work with POSIX*t objects,
see, e.g.,  ?difftime

Regards,
Martin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Date Calculation

2004-06-17 Thread Prof Brian Ripley
You have formatted the dates, so you are trying to subtract character 
strings.

Convert to Date instead (although you can subtract POSIXlt dates).

On Thu, 17 Jun 2004, Ko-Kang Kevin Wang wrote:

 Hi,
 
 I've been playing with:
  joinDate - format(strptime(as.vector(forum[,2]), %d-%b-%y),
 +%d-%b-%Y)
  today - format(strptime(as.vector(14-Jun-04), %d-%b-%Y),
 + %d-%b-%Y)
  joinDate
  [1] 04-Feb-2004 13-Feb-2004 26-Feb-2004 27-Feb-2004
 27-Feb-2004
  [6] 27-Feb-2004 29-Feb-2004 01-Mar-2004 02-Mar-2004
 07-Mar-2004
 [11] 08-Mar-2004 17-Mar-2004 20-Mar-2004 22-Mar-2004
 22-Mar-2004
 [16] 23-Mar-2004 23-Mar-2004 24-Mar-2004 01-Apr-2004
 01-Apr-2004
 [21] 01-Apr-2004 01-Apr-2004 02-Apr-2004 06-Apr-2004
 09-Apr-2004
 [26] 11-Apr-2004 14-Apr-2004 03-May-2004 04-May-2004
 30-May-2004
 [31] 01-Jun-2004 10-Jun-2004 14-Jun-2004 17-Jun-2004
 17-Jun-2004
  today
 [1] 14-Jun-0004
  joinDate - today
 Error in joinDate - today : non-numeric argument to binary operator
 
 But it didn't quite work.  What I'd like joinDate - today to return is
 the number of days to today, since joinDate.  I'm sure it has been asked
 before however a search on r-help didn't found me any relevant
 information *_*.
 
 Cheers,
 
 Kevin
 
 
 Ko-Kang Kevin Wang, MSc(Hon)
 SLC Stats Workshops Co-ordinator
 The University of Auckland
 New Zealand
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 
 

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Date Calculation

2004-06-17 Thread Ko-Kang Kevin Wang
Hi,

 -Original Message-
 From: Martin Maechler [mailto:[EMAIL PROTECTED]
 Kevin,
[[did you have tough day? usually your Q/A are much
 better ;-()]]

Thanks to those who have replied, and yes shame on me..

[I also realised I can just use Sys.Date() to get today's date,
instead of typing it in..I really had a tough day *_*]

Cheers,

Kevin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html