Using as.POSIXct in R giving na for identical character structures

I have two character timestamps that I want to convert to POSIX format in R timestamps.:

1: "2013-03-30 17:45:00"

2: "2013-03-31 02:05:00"

The first converts the penalty, the second gives me NA. timestampsloaded both charactersfrom SQL server. Does anyone have any idea what is going wrong?

I have no reputation for attaching a screenshot, so here is a screenshot of my R console showing the result: http://emillarsen.com/r%20console.jpg

+4
source share
2 answers

DST. , . 31 2013 2 3 , .

as.POSIXct("2013-03-31 02:05:00",format="%Y-%m-%d %H:%M:%S", tz="Europe/Stockholm")
[1] NA

, (CET).

+6

. , TimeZone. .
POSIXct:

  dates <- c("1992-02-27", "1992-02-27", "1992-01-14", "1992-02-28", "1992-01-02")
  times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
  X <- paste(dates, times)

  str(x)
  chr [1:5] "1992-02-27 23:03:20" "1992-02-27 22:29:56" ...

  dt <- strptime(x, "%Y-%m-%d %H:%M:%S")
  dt
[1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30"
[4] "1992-02-28 18:21:03" "1992-01-02 16:56:26"  

  str(dt) 
  POSIXlt[1:5], format: "1992-02-27 23:03:20" "1992-02-27 22:29:56" ...  

:

> now <- Sys.time()
> now
[1] "2014-01-16 16:58:23 IST"
> as.POSIXlt(as.character(now),tz="GMT")
[1] "2014-01-16 17:05:24 GMT"
> str(as.POSIXlt(now))
 POSIXlt[1:1], format: "2014-01-16 16:58:23"
> unclass(as.POSIXlt(now))
$sec
[1] 23.1636

$min
[1] 58

$hour
[1] 16

$mday
[1] 16

$mon
[1] 0

$year
[1] 114

$wday
[1] 4

$yday
[1] 15

$isdst
[1] 0

attr(,"tzone")
[1] ""    "IST" "IST"
0

All Articles