Converting difftime to numeric


I was hoping someone could help me convert difftime to numeric.
Here is a sample dataset:

     ride_idt, rip_duration

a1, 625 secs
a2, 244 secs
a3, 80 secs
a4, 702 secs
a5, 43 secs
a6, 3227 secs

Here is the class for trip_duration: $ trip_duration: 'difftime' num 625 244 80 702 ...
..- attr(*, "units")= chr "secs"
My goal is to convert that "625 secs" into the number 625.


as.numeric should do the job.

DF <- data.frame(ride_id=c("a1","a2","a3"),
                  trip_dur=as.difftime(c(625,244,80),units = "secs"))
  ride_id trip_dur
1      a1 625 secs
2      a2 244 secs
3      a3  80 secs
DF$trip_dur <- as.numeric(DF$trip_dur)
  ride_id trip_dur
1      a1      625
2      a2      244
3      a3       80

Great! It worked, thank you.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.