Skip to content
Back to formatted view

Raw Message

Message-ID: <419EED2318C2164DB95FBB20AA8810D802C032@smtp_mail.bankofamerica.com>
Date: 2013-01-16T18:53:37Z
From: Yuan, Rebecca
Subject: How to cut the time format short
In-Reply-To: <A4E5A0B016B8CB41A485FC629B633CED4A33361B33@GOLD.corp.lgc-group.com>

Hello Ellison,

Thanks very much!

I use the substr() and it works!

Have a great day!

Cheers,

Rebecca

-----Original Message-----
From: S Ellison [mailto:S.Ellison at LGCGroup.com] 
Sent: Wednesday, January 16, 2013 1:35 PM
To: Yuan, Rebecca; R help
Subject: RE: How to cut the time format short

 

> I have a time format looks like
> 31JAN2002:00:00:00.000
> How could I cut it to
> 31JAN2002

You have several options depending on what form the data are in.

Assuming it is character data, you could use substr:

substr("31JAN2002:00:00:00.000", 1, 9)

or gsub:

gsub("(.{9}).+", "\\1", "31JAN2002:00:00:00.000")

or you could convert to date and reprint:
d <- as.Date("31JAN2002:00:00:00.000", format="%d%b%Y") format(d, "%d%b%Y") 
	#albeit with lowecase month

All of those should work on vectors.
Some will work on factors but to be safe, wrap the factors in as.character() 

S Ellison

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:7}}