[R] How to seperate date and time into different columns?

Henrique Dallazuanna wwwhsd at gmail.com
Fri Jan 22 19:20:09 CET 2010


Try this:

strDate <- c('4/17/2008 16:01', '4/18/2008 17:13')
do.call(rbind, strsplit(strDate, "[[:punct:]]|\\s"))[,c(2, 1, 3:5)]


On Fri, Jan 22, 2010 at 4:09 PM, FMH <kagba2006 at yahoo.com> wrote:
> Dear All,
>
> I have a series of data in which the first column consist of a combination of date and time, for instance 17 April 2008 at 4.01pm, such data is recorded as:
>
> 4/17/2008 16:01
>
> I'd like to seperate it into four different columns which consist of Day, Month,Year and Time, respectively.
>
> Could someone please advice me on this mater?
>
> Thank you,
> Fir
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list