So, data
is a data frame consists of many columns, and one of which called lpep_pickup_datetime
has date and time in the format of "01/01/2016 12:39:36 AM"
I want to analyze these data by date and time, so I am trying to create a new column named pickup_date
and one named pickup_time
with AM or PM information.
I have used the strsplit function to split the string into the following form: c("01/01/2016", "12:29:24", "AM"), and I am trying to create the aforementioned columns out of this data.
I have wrote the following code:
data$lpep_pickup_datetime=strsplit(data$lpep_pickup_datetime, " ")
data$pickup_date=data$lpep_pickup_datetime[[1]][1]
for (i in seq(1,90181))
{
data$pickup_time[i]=data$lpep_pickup_datetime[[i]][2]
}
This is gravely inefficient, as it takes too long to iterate through 90181 rows of data. Is there a better way to accomplish this task?
Thanks.