I've got some data which is character class:
class(solarX[,MEASDATE])
[1] "character"
Which looks like :
head(solarX[,MEASDATE])
[1] "1/05/2015 0:00" "1/05/2015 0:30" "1/05/2015 1:00" "1/05/2015 1:30" "1/05/2015 2:00" "1/05/2015 2:30"
However, I don't want it in character format and need to be able to access the Hours and Minutes part of the date-time.
What i've tried is:
strptime(solarX[,MEASDATE], "%d/%m/%Y %H:%M"))
Which works great, it gives me:
[1] "2015-05-01 00:00:00 AEST" "2015-05-01 00:30:00 AEST" "2015-05-01 01:00:00 AEST" "2015-05-01 01:30:00 AEST" "2015-05-01 02:00:00 AEST"
[6] "2015-05-01 02:30:00 AEST"
class(strptime(solarX[,MEASDATE], "%d/%m/%Y %H:%M"))
[1] "POSIXlt" "POSIXt"
However, when I go to augment my original data table by doing:
solarX[, date := strptime(solarX[,MEASDATE], "%d/%m/%Y %H:%M")]
(solarX is my data table)
I get the following warning:
Warning message:
In `[.data.table`(solarX, , `:=`(date, strptime(solarX[, MEASDATE], :
Supplied 11 items to be assigned to 17568 items of column 'date' (recycled leaving remainder of 1 items)
And the data table returned looks terrible:
MEASDATE rrp exp_kwh date
1: 1/05/2015 0:00 33.99299 0 0,0,0,0,0,0,
2: 1/05/2015 0:30 31.53335 0 0,30, 0,30, 0,30,
3: 1/05/2015 1:00 29.37092 0 0,0,1,1,2,2,
4: 1/05/2015 1:30 28.03197 0 1,1,1,1,1,1,
5: 1/05/2015 2:00 26.82800 0 4,4,4,4,4,4,
6: 1/05/2015 2:30 25.22149 0 115,115,115,115,115,115,
Clearly I don't want the "date" column to look like that, rather have it filled with the values i got from the original strptime function.