On Tue, Feb 8, 2011 at 11:29 AM, Phil Spector <spec...@stat.berkeley.edu> wrote:
> Mark -
>   Here's a few possibilites:
>
>> dts = c('6/10/2009 10:04:00 AM','6/15/2009 9:47:00 AM','6/15/2009 9:47:00
>> AM')
>> as.Date(sapply(strsplit(dts,' '),'[',1),'%m/%d/%Y')
>
> [1] "2009-06-10" "2009-06-15" "2009-06-15"
>>
>> as.Date(sub('(\\d+/\\d+/\\d+) .*','\\1',dts),'%m/%d/%Y')
>
> [1] "2009-06-10" "2009-06-15" "2009-06-15"
>>
>> as.Date(sub('\\d+:\\d+:\\d+ [AP]M','',dts),'%m/%d/%Y')
>
> [1] "2009-06-10" "2009-06-15" "2009-06-15"
>>
>> as.Date(as.POSIXct(dts,format='%m/%d/%Y %H:%M:%S %p'))
>
> [1] "2009-06-10" "2009-06-15" "2009-06-15"
>
>                                        - Phil Spector
>                                         Statistical Computing Facility
>                                         Department of Statistics
>                                         UC Berkeley
>                                         spec...@stat.berkeley.edu
>
>

Thanks for a lot of good ideas!

Cheers,
Mark

______________________________________________
R-help@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.

Reply via email to