[R] chron - when seconds data not included

Tubin sredmonson at yahoo.com
Tue Dec 9 20:43:45 CET 2008


Works like a charm!  Thanks.


Gabor Grothendieck wrote:
> 
> On Mon, Dec 8, 2008 at 11:52 PM, Tubin <sredmonson at yahoo.com> wrote:
>>
>> I have date and time data which looks like this:
>>
>>      [,1]     [,2]
>>  [1,] "7/1/08" "9:19"
>>  [2,] "7/1/08" "9:58"
>>  [3,] "7/7/08" "15:47"
>>  [4,] "7/8/08" "10:03"
>>  [5,] "7/8/08" "10:32"
>>  [6,] "7/8/08" "15:22"
>>  [7,] "7/8/08" "15:27"
>>  [8,] "7/8/08" "15:40"
>>  [9,] "7/9/08" "10:25"
>> [10,] "7/9/08" "10:27"
>>
>> I would like to use chron on it, so that I can calculate intervals in
>> time.
>>
>> I can't seem to get chron to accept the time format that doesn't include
>> seconds.  Do I have to go through and append :00 on every line in order
>> to
>> use chron?
> 
> 
> 
> That's one way:
> 
> m <- matrix( c("7/1/08","9:19",
>   "7/1/08","9:58",
>   "7/7/08","15:47",
>   "7/8/08","10:03",
>   "7/8/08","10:32",
>   "7/8/08","15:22",
>   "7/8/08","15:27",
>   "7/8/08","15:40",
>   "7/9/08","10:25",
>   "7/9/08","10:27"), nc = 2, byrow = TRUE)
> 
> chron(m[,1], paste(m[,2], 0, sep = ":"))
> 
> # another is to use as.chron
> 
> as.chron(apply(m, 1, paste, collapse = " "), "%m/%d/%y %H:%M")
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/chron---when-seconds-data-not-included-tp20908803p20922004.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list