Converting from Factor into Datetime object in R
I want to convert my Factor that contains TimeStamps that got created in another application by a basic Java function into R Datetime objects. I use a German Windows Vista.
At the moment I tried two lines without success:
as.POSIXlt(as.character(Time), format="%b %d, %Y %T %r")
as.POSIXlt(Time, format="%b %d, %Y %T %r")
My dataset Time looks like:
structure(c(24L, 25L, 28L, 27L, 26L, 1L, 2L, 3L, 4L, 5L, 6L,
8L, 7L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 30L, 29L, 42L, 52L, 53L, 54L, 55L, 56L, 31L,
33L, 32L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L,
46L, 47L, 48L, 49L, 50L, 51L), .Label = c("Apr 10, 2011 10:29:46 AM",
"Apr 11, 2011 8:30:51 AM", "Apr 12, 2011 10:16:07 AM", "Apr 13, 2011 9:45:57 AM",
"Apr 14, 2011 9:05:56 AM", "Apr 15, 2011 8:30:40 AM", "Apr 16, 2011 11:31:42 AM",
"Apr 16, 2011 2:24:58 AM", "Apr 17, 2011 1:55:50 AM", "Apr 17, 2011 12:30:23 PM",
"Apr 18, 2011 11:13:29 AM", "Apr 19, 2011 8:25:42 AM", "Apr 20, 2011 9:41:59 AM",
"Apr 21, 2011 10:51:01 AM", "Apr 22, 2011 11:01:45 AM", "Apr 23, 2开发者_运维技巧011 11:33:41 AM",
"Apr 24, 2011 11:36:11 AM", "Apr 25, 2011 1:33:56 PM", "Apr 26, 2011 9:42:21 AM",
"Apr 27, 2011 9:41:53 AM", "Apr 28, 2011 9:20:51 AM", "Apr 29, 2011 7:51:15 AM",
"Apr 30, 2011 11:43:58 AM", "Apr 7, 2011 9:48:31 AM", "Apr 8, 2011 9:43:02 AM",
"Apr 9, 2011 11:28:28 PM", "Apr 9, 2011 11:42:25 AM", "Apr 9, 2011 2:10:59 AM",
"May 1, 2011 11:58:41 AM", "May 1, 2011 3:33:16 AM", "May 10, 2011 9:31:42 AM",
"May 11, 2011 7:00:21 PM", "May 11, 2011 9:31:11 AM", "May 12, 2011 9:22:29 AM",
"May 13, 2011 8:46:17 AM", "May 14, 2011 12:40:50 PM", "May 15, 2011 2:36:01 PM",
"May 16, 2011 8:53:11 AM", "May 17, 2011 9:53:00 AM", "May 18, 2011 10:20:52 AM",
"May 19, 2011 9:42:22 AM", "May 2, 2011 8:45:46 AM", "May 20, 2011 1:13:02 PM",
"May 21, 2011 1:10:48 PM", "May 22, 2011 11:31:44 AM", "May 23, 2011 10:10:04 AM",
"May 24, 2011 10:11:29 AM", "May 25, 2011 9:30:45 AM", "May 26, 2011 9:30:51 AM",
"May 27, 2011 9:01:07 AM", "May 28, 2011 11:27:56 AM", "May 3, 2011 8:21:01 AM",
"May 4, 2011 8:11:23 AM", "May 5, 2011 10:10:55 AM", "May 6, 2011 8:01:03 AM",
"May 9, 2011 9:13:38 AM"), class = "factor")
sessionInfo()
R version 2.10.1 (2009-12-14)
i386-pc-mingw32
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_2.10.1
What's the problem?
I think %T
and %r
are redundant. Try this:
as.POSIXlt(as.character(Time), format="%b %d, %Y %r")
Also note (from ?strptime
) that some formatting characters not supported (for output) on Windows.
精彩评论