0
我有一個名爲x
變量是這樣的:爲什麼不能在tbl_df中將lubridate轉換日期?
x <- structure(list(Time = c("2002-05-07 21:00", "2002-05-08 21:00",
"2002-05-09 21:00", "2002-05-10 21:00",
"2002-05-11 21:00", "2002-05-13 21:00",
"2002-05-14 21:00", "2002-05-15 21:00",
"2002-05-16 21:00", "2002-05-17 21:00")),
.Names = "Time", class = c("tbl_df", "data.frame"),
row.names = c(NA, -10L))
現在,我想在字符串轉換中x
爲日期,由於x[1,1] %>% lubridate::ymd_hm()
讓我對單個元素預期的結果,我認爲下面會做的伎倆:
x %>% lubridate::ymd_hm()
但它不工作(結果是NA),我得到以下警告:
Warning message:
All formats failed to parse. No formats found.
爲什麼x %>% lubridate::ymd_hm()
不按我期望的方式工作,我該怎麼做才能得到我想要的結果?
您的數據已被截斷。 –
@NickK感謝您發現它。我已經修復它。 – mauna
'ymd_hm(x $時間)'工作得很好。你爲什麼會認爲'x%>%lubridate :: ymd_hm()'會知道'Time'列? – hrbrmstr