Pretty basic, just not understanding what the tz argument is for if not for this...
dateIWantToConvert <- as.Date("2013-06-01") #the format of my starting object
as.POSIXlt(dateIWantToConvert, tz="America/Chicago")
[1] "2013-06-01 UTC"
There are a whole lot of these in a data.frame, so efficiency is important.
A more reliable way to do this is to use strptime. This takes any tz arguement from OlsonNames(). And by reliable, I mean that this should be OS independent.
(vec.Date <- strptime("2013-06-01", format = "%Y-%m-%d", tz = "America/Chicago"))
# "2013-06-01 CDT"
class(vec.Date)
# [1] "POSIXlt" "POSIXt"
And for your question regarding efficiency, you really should be using strptime. See Difference between as.POSIXct/as.POSIXlt and strptime for converting character vectors to POSIXct/POSIXlt
You could try without as.Date():
> as.POSIXlt("2013-06-01", tz="America/Chicago")
#[1] "2013-06-01 CDT"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With