[R] Getting the month out of my date as a number not characters

2009-07-02 Thread Tim Chatterton
I have a data frame (hf) that is all set up and the dates are working fine - however I need to extract the months and hours (2 separate columns) as numbers - however they are coming out as characters. I have tried both the following: hf50$hour= hf50$date hf50$hour=format(hf50[hour],%H) and

[R] Getting the month out of my date as a number not characters

2009-07-02 Thread Tim Chatterton
I have a data frame (hf) that is all set up and the dates are working fine - however I need to extract the months and hours (2 separate columns) as numbers - however they are coming out as characters. I have tried both the following: hf50$hour - hf50$date hf50$hour - format(hf50[hour],%H)

Re: [R] Getting the month out of my date as a number not characters

2009-07-02 Thread Don MacQueen
Try hf$hour - as.POSIXlt(hf$date)$hour hf$month - as.POSIXlt(hf$date)$mon+1 To see why, use the man pages to study the structure of POSIXlt objects. Try: tmp - strptime(20/2/06 11:16:16.683, %d/%m/%y %H:%M:%OS) unclass(tmp) For example: tmp - strptime(20/2/06 11:16:16.683,