#This my look trivial but has been killing my time
#I want to extract most current and old date from mydates #variable that has
more than 10,000 observation.
#Get days
# use as.Date( ) to convert strings to dates
mydates <- as.Date(c("2007-06-22", "2007-05-21",
"2004-04-13", "2004-03-11","2004-02-13",))
#Is there a way/fuction to extract mostcurrent date
#from mydates variable
mostcurrent <- as.Date(c("2007-06-22"))
#Is there a way/function to extract olddate
#from mydates variable
olddate <- as.Date(c("2004-02-13"))
#Days between most current and old dayte
days <- as.numeric(mostcurrent - olddate)
Peter Maclean
Department of Economics
UDSM
[[alternative HTML version deleted]]
If I read this correctly:
mydates <- as.Date(c("2007-06-22", "2007-05-21",
"2004-04-13",
"2004-03-11","2004-02-13"))
xx <- min(mydates)
yy <- max(mydates)
yy-xx
John Kane
Kingston ON Canada
> -----Original Message-----
> From: pmaclean2011 at yahoo.com
> Sent: Sun, 28 Jul 2013 12:20:30 -0700 (PDT)
> To: r-help at r-project.org
> Subject: Re: [R] Extracting Current and Old Date
>
> #This my look trivial but has been killing my time
> #I want to extract most current and old date from mydates #variable that
> has more than 10,000 observation.
> #Get days
> # use as.Date( ) to convert strings to dates
> mydates <- as.Date(c("2007-06-22", "2007-05-21",
"2004-04-13",
> "2004-03-11","2004-02-13",))
> #Is there a way/fuction to extract mostcurrent date
> #from mydates variable
> mostcurrent <- as.Date(c("2007-06-22"))
>
> #Is there a way/function to extract olddate
> #from mydates variable
> olddate <- as.Date(c("2004-02-13"))
>
> #Days between most current and old dayte
> days <- as.numeric(mostcurrent - olddate)
>
>
> Peter Maclean
> Department of Economics
> UDSM
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email to find out more!
On Jul 28, 2013, at 12:20 PM, Peter Maclean wrote:> #This my look trivial but has been killing my time > #I want to extract most current and old date from mydates #variable that has more than 10,000 observation. > #Get days > # use as.Date( ) to convert strings to dates > mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", "2004-03-11","2004-02-13",)) > #Is there a way/fuction to extract mostcurrent date > #from mydates variable > mostcurrent <- as.Date(c("2007-06-22")) > > #Is there a way/function to extract olddate > #from mydates variable > olddate <- as.Date(c("2004-02-13")) > > #Days between most current and old dayte > days <- as.numeric(mostcurrent - olddate)The usual ways to work with numeric data have been given .Date methods:> mydates <- as.Date(c("2007-06-22", "2007-05-21", "2004-04-13", "2004-03-11","2004-02-13")) > min(mydates)[1] "2004-02-13"> max(mydates)[1] "2007-06-22"> range(mydates)[1] "2004-02-13" "2007-06-22"> diff(range(mydates))Time difference of 1225 days -- David Winsemius Alameda, CA, USA
Hi,
?max
?min
max(mydates)
#[1] "2007-06-22"
min(mydates)
#[1] "2004-02-13"
?max(mydates)-min(mydates)
Time difference of 1225 days
?max(as.numeric(mydates))-min(as.numeric(mydates))
#[1] 1225
A.K.
----- Original Message -----
From: Peter Maclean <pmaclean2011 at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Sunday, July 28, 2013 3:20 PM
Subject: Re: [R] Extracting Current and Old Date
#This my look trivial but has been killing my time
#I want to extract most current and old date from mydates #variable that has
more than 10,000 observation.?
#Get days
# use as.Date( ) to convert strings to dates
mydates <- as.Date(c("2007-06-22", "2007-05-21",
"2004-04-13", "2004-03-11","2004-02-13",))
#Is there a way/fuction to extract mostcurrent date
#from mydates variable
mostcurrent <- as.Date(c("2007-06-22"))
#Is there a way/function to extract olddate
#from mydates variable
olddate??? <- as.Date(c("2004-02-13"))
#Days between most current and old dayte
days <- as.numeric(mostcurrent - olddate) ?
Peter Maclean
Department of Economics
UDSM
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.