Another newbie question, I'm afraid. I'm trying to create new variables with "lubridate" and have run into 3 issues.
I start with a variable "time" imported as a factor in the format H:MM:SS or HH:MM:SS. I also created "timeC" as a character.
1. Display issue
temp$time2 <- hms(temp$time) #take my original variable "time" and convert
Problem: only the seconds portion of "time2" displays on the screen, although it appears to be correct "under the hood":
time2
----
4
> temp$time2[1,]
[1] "7H 0M 4S"
2. Extract hours Issue
temp$hour <- hour(temp$time2) #extract just the hours portion
Problem: this works intermittently; sometimes it's fine, sometimes I get the following error:
Error in as.POSIXlt.character(as.character(x), ...) :
character string is not in a standard unambiguous format
This is concerning to me because this doesn't seem like the kind of message lubridate should be throwing.
3. Extract hour and minutes Issue
temp$hourMins <- hm(temp$time2)
Problem: every value of hourMins is "NA"
I've probably invested 4+ hours trying to figure this out and am wondering if there is another package that can support what I'm trying to do.
Any advice would be most appreciated. Thanks in advance and regards!
hms()
andhm()
) with extracting components from that time (hours()
,minutes()
,seconds()
) – hadley