Reputation: 550
I have a dataset with six variables. The first and second variables are date variables:
var1
is date in format dd/mm/yyyy
var2
is time in format hh:mm:ss
How can I merge this two variables in one correct date-variable?
Here an example of the dataset:
> IVE_tickbidask[1,]
V1 V2 V3 V4 V5 V6
1 09/28/2009 09:30:00 50.79 50.7 50.79 100
Upvotes: 0
Views: 1196
Reputation: 81683
You can use paste
to combine both strings and strptime
to generate a time object.
IVE_tickbidask <- transform(IVE_tickbidask,
time = strptime(paste(V1, V2), "%m/%d/%Y %H:%M:%S"))
str(IVE_tickbidask)
'data.frame': 1 obs. of 7 variables:
$ V1 : Factor w/ 1 level "09/28/2009": 1
$ V2 : Factor w/ 1 level "09:30:00": 1
$ V3 : num 50.8
$ V4 : num 50.7
$ V5 : num 50.8
$ V6 : int 100
$ time: POSIXct, format: "2009-09-28 09:30:00"
Upvotes: 4