[R] time extraction and normalization

Simon Knapp sleepingwell at gmail.com
Tue Oct 16 07:32:41 CEST 2012

toDaySecond <- function(date.string, format.string='%d%b%Y:%T', tz='') {
    d <- as.POSIXct(d, format=format.string, tz=tz)
    sum(mapply(function(f, l) as.numeric(format(d, format=f)) * l,
c('%H', '%M', '%S'), c(3600, 60, 1)))


Will calculate the second of the day. divide by 3600 to convert to hours.

On Tue, Oct 16, 2012 at 4:21 PM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> There are multiple ways. For lack of your example, I would suggest multiplying by 24.
> Please post the previous context of the thread if you must post from Nabble.
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
> york8866 <yu_york at hotmail.com> wrote:
>>The code gives the numbers in "days", how can I adjust the code to
>>get the numbers in "hours"?
>>I tried units but it did not work.
>>View this message in context:
>>Sent from the R help mailing list archive at Nabble.com.
>>R-help at r-project.org mailing list
>>PLEASE do read the posting guide
>>and provide commented, minimal, self-contained, reproducible code.
> ______________________________________________
> 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.

More information about the R-help mailing list