When I try to coerce a POSIXct
date-time to a Date
using as.Date
, it seems to return wrong date.
I suspect it has got something to do with the time zone. I tried the tz
argument in as.Date
, but it didn't give the expected date.
# POSIXct returns day of month 24
data$Time[3]
# [1] "2020-03-24 00:02:00 IST"
class(data$Time[3])
# [1] "POSIXct" "POSIXt"
# coerce to Date, returns 23
as.Date(data$Time[3])
# [1] "2020-03-23"
# try the time zone argument, without luck
as.Date(data$Time[3], tz = "IST")
# [1] "2020-03-23"
# Warning message:
# In as.POSIXlt.POSIXct(x, tz = tz) : unknown timezone 'IST'
Sys.timezone()
# [1] "Asia/Calcutta"
Any ideas what may be going wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…