Reputation: 105
The first column is the day of the year and the second column is the time (ie. 2355 denotes 23:55, 0 is 00:00, 59 is 00:59 minutes): year of measurement=2011
2,2355,2.701
2,2356,2.701
2,2357,2.737
2,2358,2.805
2,2359,2.821
3,0,2.847
3,1,2.881
.
.
3,59,3.3
3,100,2.2
3,101,2.8
.
.
3,159,3.0
3,200,3.1
I want to merge column 1 and 2 using datetime classes in R such that I get one single column starting with %Y-%m-%d %H:%M:%S
i tried
datetime <- paste(2011, df$V1, df$V2, sep="-")
strptime(datetime, format="%Y-%j-%M")
but not getting the desired output. Any comments where i am going wrong?
Cheers,
Navin
Upvotes: 1
Views: 174
Reputation: 263301
In addtion to putting in the hour format spec, you need to pad the V2 values with leading 0's.
> datetime <- paste(2011, dat$V1, sprintf("%00004d",dat$V2), sep="-")
> strptime(datetime, format="%Y-%j-%H%M")
[1] "2011-01-02 23:55:00" "2011-01-02 23:56:00" "2011-01-02 23:57:00" "2011-01-02 23:58:00"
[5] "2011-01-02 23:59:00" "2011-01-03 00:00:00" "2011-01-03 00:01:00" "2011-01-03 00:59:00"
[9] "2011-01-03 01:00:00" "2011-01-03 01:01:00" "2011-01-03 01:59:00" "2011-01-03 02:00:00"
Upvotes: 3