[R] Reading time/date string
Matthew Walker
m.g.walker at massey.ac.nz
Thu Aug 9 09:07:07 CEST 2007
Thanks Mark, that was very helpful. I'm now sooooo close!
Can anyone tell me how to extract the "value" from an instance of a
"difftime" class? I can see the value, but how can I place it in a
dataframe?
> time_string1 <- "10:17:07 02 Aug 2007"
> time_string2 <- "13:17:40 02 Aug 2007"
>
> time1 <- strptime(time_string1, format="%H:%M:%S %d %b %Y")
> time2 <- strptime(time_string2, format="%H:%M:%S %d %b %Y")
>
> time_delta <- difftime(time2,time1, unit="sec")
> time_delta
Time difference of 10833 secs # <--- I'd like this value just here!
>
> data.frame(time1, time2, time_delta)
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class "difftime" into a data.frame
Thanks again,
Matthew
Mark W Kimpel wrote:
> Look at some of these functions...
>
> DateTimeClasses(base) Date-Time Classes
> as.POSIXct(base) Date-time Conversion Functions
> cut.POSIXt(base) Convert a Date or Date-Time Object to a Factor
> format.Date(base) Date Conversion Functions to and from Character
>
> Mark
> ---
>
> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
> Indiana University School of Medicine
>
> 15032 Hunter Court, Westfield, IN 46074
>
> (317) 490-5129 Work, & Mobile & VoiceMail
> (317) 663-0513 Home (no voice mail please)
>
> ******************************************************************
>
> Matthew Walker wrote:
>> Hello everyone,
>>
>> Can anyone tell me what function I should use to read time/date
>> strings and turn them into a form such that I can easily calculate
>> the difference of two? The strings I've got look like "10:17:07 02
>> Aug 2007". If I could calculate the number of seconds between them
>> I'd be very happy!
>>
>> Cheers,
>>
>> Matthew
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> .
>
More information about the R-help
mailing list