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

Tim Chatterton tim.chatterton at uwe.ac.uk
Thu Jul 2 12:40:23 CEST 2009


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

hf$month <- as.POSIXct(strptime(hf$date, format = "%m"))

but they are still coming out as characters.

Any ideas please?
Thanks,
Tim.




More information about the R-help mailing list