Every row has a different origintimezone. I need to make use of the standardformat_new column which is in the origintimezone time to create a new column where the time follows the com_timezonenames.
A simplified version would be something like this
a = ymd_hms('2017-10-10 10:20:00',tz = 'Australia/Sydney')
a
with_tz(a, tz = 'Singapore')
[![enter image description here][2]][2]
However, when I'm applying a similar code to that above, I am met with the following error.
[![enter image description here][3]][3]
I have tried making a for loop to run the whole list but the dataset of over a few hundred thousand makes it unfeasible.
REPREX as reqeusted This is what i have initially.
[![enter image description here][4]][4]
structure(list(com_country = c("SG", "AU", "NZ", "UK", "AU",
"AU"), orderdate_local = c("9/20/2017 4:47:35 AM", "9/30/2017 7:00:00 AM",
"9/20/2017 1:37:14 AM", "9/18/2017 9:38:34 PM", "9/30/2017 3:07:29 AM",
"9/30/2017 10:17:01 AM"), origincountry = c("US", "AU", "UK",
"AU", "AU", "AU")), .Names = c("com_country", "orderdate_local",
"origincountry"), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
orderdate_local is given in the origincountry timezone so i need to include map the country code over to the tz value.
##getting origin timezone from countrycode
dd$origintimezone <- mapvalues(dd$origincountry,
from=c("AU", "UK", "US"),
to=c("Australia/Sydney","Europe/London","America/Toronto"))
thereafter i need to convert orderdate_local into the standard POSIXlt format so i can use the strptime function
dd$standardformat_new <- strptime(dd$orderdate_local,format="%m/%d/%Y
%I:%M:%S %p")
dd$com_timezonenames <- mapvalues(dd$com_country,
from=c("AU","MY","NZ","SG","PH","HK","UK","TH"),
to=c("Australia/Sydney", "Asia/Kuala_Lumpur", "Pacific/Auckland","Asia/Singapore","Asia/Manila","Asia/Hong_Kong","Europe/London","Asia/Bangkok"))