Is there a simple way to obtain the time of day in R? I want the time of day for computational purposes, not for display. I want to be able to create code like the following: if (time_of_day >= 22:00 & time_of_day <= 06:00) then X otherwise Y I realize I could parse a date/time object and extract the time, but hopefully other people have already done this, or there is a straightforward representation of time of day in R that I have not been able to find in the documentation. Thanks. [[alternative HTML version deleted]]
On 25/06/2013 06:59, Rguy wrote:> Is there a simple way to obtain the time of day in R? I want the time of > day for computational purposes, not for display. I want to be able to > create code like the following: > > if (time_of_day >= 22:00 & time_of_day <= 06:00) then X otherwise Ywhich will not parse and in any case there are no such times.> I realize I could parse a date/time object and extract the time, but > hopefully other people have already done this, or there is a > straightforward representation of time of day in R that I have not been > able to find in the documentation.> t <- Sys.time() > tt <- format(t, "%H:%M") > tt <= "22:00" && tt >= "06:00" [1] TRUE Note the use of && not &.> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.PLEASE do: no HTML mail .... -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Tue, 25 Jun 2013, Rguy <rguy at 123mail.org> writes:> Is there a simple way to obtain the time of day in R? I want the time of > day for computational purposes, not for display. I want to be able to > create code like the following: > > if (time_of_day >= 22:00 & time_of_day <= 06:00) then X otherwise Y^^^^^ ^^^^^ this will not work: the times need to be something that R understands, eg, numeric values such as 2200 or character values such as "22:00"> > I realize I could parse a date/time object and extract the time, but > hopefully other people have already done this, or there is a > straightforward representation of time of day in R that I have not been > able to find in the documentation.strftime(Sys.time(), "%H:%M") -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net
Seemingly Similar Threads
- Basic astronomy package recommendation wanted.
- Packages for Learning Algorithm Independent Branch and Bound for Feature Selection
- Packages for Learning Algorithm Independent Branch and Bound for Feature Selection
- Open a file which name contains a tilde
- Open a file which name contains a tilde