For some reason this seems to work: d <- "04MAY2011:08:19:00" toDaySecond(d)
John Kane Kingston ON Canada > -----Original Message----- > From: [email protected] > Sent: Tue, 16 Oct 2012 05:22:29 -0700 (PDT) > To: [email protected] > Subject: Re: [R] time extraction and normalization > > Hi Simon, > I tried your code, but I am getting some error message: > toDaySecond('04MAY2011:08:19:00') > #Error in as.POSIXct(d, format = format.string, tz = tz) : > #object 'd' not found > > A.K. > > > > > ----- Original Message ----- > From: Simon Knapp <[email protected]> > To: Jeff Newmiller <[email protected]> > Cc: [email protected]; york8866 <[email protected]> > Sent: Tuesday, October 16, 2012 1:32 AM > Subject: Re: [R] time extraction and normalization > > 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))) > } > > toDaySecond('04MAY2011:08:19:00') > > 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 > <[email protected]> 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:<[email protected]> 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 <[email protected]> wrote: >> > >>Thanks, >>> > >>The code gives the numbers in "days", how can I adjust the code to > >>directly > >>get the numbers in "hours"? >>> > >>I tried units but it did not work. >>> > >>Thanks1 >>> >>> >>> > >>-- > >>View this message in context: > >>http://r.789695.n4.nabble.com/time-extraction-and-normalization-tp4646275p4646298.html > >>Sent from the R help mailing list archive at Nabble.com. >>> > >>______________________________________________ > >>[email protected] 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. >> >> ______________________________________________ >> [email protected] 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. > > ______________________________________________ > [email protected] 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. > > > ______________________________________________ > [email protected] 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. ____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails ______________________________________________ [email protected] 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.

