[R] Changing character into date

Rui Barradas ruipbarradas at sapo.pt
Sun Aug 12 13:03:52 CEST 2012


Hello,

There are two or three simple ways.

x <- c("2012-08-09 22:23:00", "2012-08-09 22:24:00")
#1st: dates without times
as.Date(x)
[1] "2012-08-09" "2012-08-09"

#2nd: dates and times and time zones.
#    Too big for axis tick marks?
as.POSIXct(x)
[1] "2012-08-09 22:23:00 BST" "2012-08-09 22:24:00 BST"

#3rd: using ?format.POSIXct you can do whatever you want.
y <- as.POSIXct(x)
format(y, format = "%m/%Y")
format(y, format = "%b/%Y")

Hope this helps.

Rui Barradas

Em 12-08-2012 06:33, Erin Hodgess escreveu:
> Dear R People:
>
> I have a column in a data frame that has date and time (one per
> minute), such as "2012-08-09 22:23:00 2012-08-09 22:24:00" etc.
>
> What is the best way to change that into numeric dates to be used as
> an x-axis, please?
>
> I've been looking at as.Date and as.Date.numeric, but those are for
> monthly/yearly data.
>
> Thanks for any help in advance!
> Sincerely,
> Erin
>
>



More information about the R-help mailing list