[R] Working with date

arun smartpink111 at yahoo.com
Thu Dec 27 04:03:07 CET 2012


Hi Jim,
Sorry, it fails.

Tx for catching.
 asd1 <- as.Date(c("2012-01-03","2012-12-25","2012-01-12","2012-10-01"))
gsub("(.*/)0(.*/.*)","\\1\\2",gsub("^0(.*/.*/.*)","\\1",format(asd1,"%d/%m/%Y")))
#[1] "3/1/2012"   "25/12/2012" "12/1/2012"  "1/10/2012" 

A.K.





----- Original Message -----
From: Jim Holtman <jholtman at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: Ron Michael <ron_michael70 at yahoo.com>; R help <r-help at r-project.org>
Sent: Wednesday, December 26, 2012 9:38 PM
Subject: Re: [R] Working with date

what happens with   25/12/2012?

Sent from my iPad

On Dec 26, 2012, at 20:22, arun <smartpink111 at yahoo.com> wrote:

> Hi,
> gsub("^\\d(.*/)\\d(.*/.*)","\\1\\2",format(asd,"%d/%m/%Y"))
> #[1] "3/1/2012"
> A.K.
> 
> 
> 
> 
> ----- Original Message -----
> From: Ron Michael <ron_michael70 at yahoo.com>
> To: jim holtman <jholtman at gmail.com>
> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Wednesday, December 26, 2012 2:25 PM
> Subject: Re: [R] Working with date
> 
> Thanks Jim for your reply.
> 
> However I want "3/1/2012" not "03/01/2012"
> 
> Any idea ?
> 
> Thanks
> 
> 
> ----- Original Message -----
> From: jim holtman <jholtman at gmail.com>
> To: Ron Michael <ron_michael70 at yahoo.com>
> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Thursday, 27 December 2012 1:01 AM
> Subject: Re: [R] Working with date
> 
> forgot you were asking for mdy format
> 
>> # interchange day and month
>> format(asd, format = '%d/%m/%Y')
> [1] "03/01/2012"
>> 
> 
> 
> On Wed, Dec 26, 2012 at 2:14 PM, jim holtman <jholtman at gmail.com> wrote:
>> try this:
>> 
>>> asd <- as.Date("2012-01-03")
>>> asd
>> [1] "2012-01-03"
>>> format(asd, format = '%m/%d/%Y')
>> [1] "01/03/2012"
>>> 
>> 
>> 
>> 
>> On Wed, Dec 26, 2012 at 1:31 PM, Ron Michael <ron_michael70 at yahoo.com> wrote:
>>> asd <- as.Date("2012-01-03")
>> 
>> 
>> 
>> --
>> Jim Holtman
>> Data Munger Guru
>> 
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> 
> 
> ______________________________________________
> 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.
> 
> 
> ______________________________________________
> 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.





More information about the R-help mailing list