[R] generating a sequence of seconds

John McKown john.archie.mckown at gmail.com
Tue Aug 12 21:44:58 CEST 2014


On Tue, Aug 12, 2014 at 2:40 PM, John McKown
<john.archie.mckown at gmail.com> wrote:
<snip>
> You can simply make that a function
>
> getTimePortion <- function(POSIXct_value) {
>                             value_in_seconds=as.integer(POSIXct_value);
>                             sprintf("%02d:%02d:%02d", # C-style
> formatting string
>                                      seconds_vector/3600, # hour value
>                                      (seconds_vector%%3600)/60, #minute value
>                                      seconds_vector%%60); #second value
>                   };
>

Sorry, cut'n'pasted that incorrectly

getTimePortion <- function(POSIXct_value) {
                            value_in_seconds=as.integer(POSIXct_value);
                            sprintf("%02d:%02d:%02d", # C-style
                                     value_in_seconds/3600, # hour value
                                     (value_in_seconds%%3600)/60, #minute value
                                     value_in_seconds_vector%%60); #second value
                  };

And the above is "vectorized" and will work if argument has multiple
values in it.

-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! <><
John McKown



More information about the R-help mailing list