6

data.frame には、次の形式の日時スタンプがあります。

head(x$time)
[1] "Thu Oct 11 22:18:02 2012" "Thu Oct 11 22:50:15 2012" "Thu Oct 11 22:54:17 2012"
[4] "Thu Oct 11 22:43:13 2012" "Thu Oct 11 22:41:18 2012" "Thu Oct 11 22:15:19 2012"

as.Datelubridate、またはzooで変換しようとするたびに、 NAsまたはエラーが発生します。

今回は読みやすい形に変換する方法は?

私はもう試した:

 Time<-strptime(x$time,format="&m/%d/%Y  %H:$M")
    x$minute<-parse_date_time(x$time)
    x$minute<-mdy(x$time)
    x$minute<-as.Date(x$time,"%m/%d/%Y %H:%M:%S")
    x$minute<-as.time(x$time)
    x$minute<-as.POSIXct(x$time,format="%H:%M")
    x$minute<-minute(x$time)
4

2 に答える 2

18

あなたが本当に欲しいのはstrptime(). 次のようなものを試してください:

strptime(x$time, "%a %b %d %H:%M:%S %Y")

でできる興味深いことの例として、strptime()次のことを検討してください。

thedate <- "I came to your house at 11:45 on January 21, 2012."
strptime(thedate, "I came to your house at %H:%M on %B %d, %Y.")
# [1] "2012-01-21 11:45:00"
于 2012-10-12T17:07:14.813 に答える