I am trying to split a column of date timestamp data into two individual columns. I have several columns that have date timestamp info. The first one, I was able to use the following and it worked with no problem:
delivered$order_date<-as.Date(delivered$order_purchase_timestamp)
delivered$order_time<-format(as.POSIXct(delivered$order_purchase_timestamp),
format = "%H:%M:%S")
The "order_purchase_timestamp" column is what I split into two separate columns called order_date and order_time. Again, this worked with no problem.
However, when I tried to split three other columns that had date timestamp info combined, I get this error:
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
This seems to be only happening for the timestamp portion of the column; the "date" portion splits into its own column with no problem.
I watched a YouTube video on how to fix the error (convert the character string to a numeric string) but the example did NOT cover how to do this with a column of date timestamp data. This is the code the video suggested I use:
date<-as.numeric(as.character(date)), where "date" would be order_approved_numeric for my purposes. I entered the following code to fix my problem:
#to fix character string error msg, must convert character string to numeric
approved_time_numeric <- as.numeric(as.character(delivered$order_approved_at))
#order_approved_at is the column in the dataset that contains the date timestamp data
I got this error: Warning message:
NAs introduced by coercion
I then ran the entire code, both for the date and for the timestamp:
delivered$approved_date<-as.Date(delivered$order_approved_at)
delivered$approved_time<-format(as.POSIXct(approved_time_numeric),
format = "%H:%M:%S")
When I look at the revised dataset, it shows a new column called approved_time but it just has NA all the way down the column.
Any suggestions and advice is greatly appreciated.