I have a vector of dates I am trying to cast into datetime using lubridate. Some of these are in different timezones, so I have another variable of the same length using appropriate timezones.
By default, it seems like lubridate tz does not deal with getting a vector input:
Error in C_force_tz(time, tz = tzone, roll) :
`tz` argument must be a single character string
In addition: Warning message:
In if (tz != "UTC") { :
the condition has length > 1 and only the first element will be used
I believe there is an lapply solution, and I can conjure up a for loop for this, but I'm convinced there's an elegant way to do this!
Update: I've been working on this, and have a clunky for loop solution, as well as quite a few that surprisingly don't work.
We've established this one:
a = data.frame(time, timezones, stringsAsFactors = FALSE)
a$time_cast = ymd_hms(a$time)
# This works!
for (count in 1:nrow(a)){
tz(a$time_cast[count]) = a$timezones[count]
}
a
a$time_cast
For now I'm going to continue my work with this, but appreciate any and all ways to NOT be doing this