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

jim holtman jholtman at gmail.com
Fri Jan 22 19:22:30 CET 2010


> x <- as.POSIXct('4/17/2008 16:01', format='%m/%d/%Y %H:%M')
> x
[1] "2008-04-17 16:01:00 EDT"
> # now create a four element vector of your desired values
> y <- strsplit(format(x, "%d %m %Y %H:%M"), ' ')
> y
[[1]]
[1] "17"    "04"    "2008"  "16:01"

>


On Fri, Jan 22, 2010 at 1: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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list