Skip to content
Prev 303172 / 398503 Next

Changing character into date

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: