I use POSIXct for datetimes. Is thee a timeAlign function that I can use where : align by year direction -1 ==> start of this year direction 1 ==> start of next year align by week direction -1 ==> date on last sunday direction 1 ==> date on next sunday align by day direction -1 ==> time at past midnight direction 1 ==> time at this comming midnight
Try this. dd <- Sys.time() # test data lt <- as.POSIXlt(dd) ISOdate(1900+lt$year, 1, 1, 0, tz = "") ISOdate(1901+lt$year, 1, 1, 0, tz = "") seq(now, length = 2, by = paste("-", lt$wday, " day", sep =""))[2] seq(now, length = 2, by = paste(7-lt$wday, "day"))[2] with(lt, ISOdate(1901+year, mon, mday, 0, tz = "")) with(lt, ISOdate(1901+year, mon, mday, 23, 59, 59, tz = ""))+1 On 4/10/06, Omar Lakkis <uofiowa at gmail.com> wrote:> I use POSIXct for datetimes. Is thee a timeAlign function that I can > use where : > > align by year > direction -1 ==> start of this year > direction 1 ==> start of next year > align by week > direction -1 ==> date on last sunday > direction 1 ==> date on next sunday > align by day > direction -1 ==> time at past midnight > direction 1 ==> time at this comming midnight > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
On 4/10/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> Try this. > > dd <- Sys.time() # test data > > lt <- as.POSIXlt(dd) > > ISOdate(1900+lt$year, 1, 1, 0, tz = "") > ISOdate(1901+lt$year, 1, 1, 0, tz = "") > > seq(now, length = 2, by = paste("-", lt$wday, " day", sep =""))[2] > seq(now, length = 2, by = paste(7-lt$wday, "day"))[2]The last two lines should be (same as above but the variable name is called lt): seq(lt, length = 2, by = paste("-", lt$wday, " day", sep =""))[2] seq(lt, length = 2, by = paste(7-lt$wday, "day"))[2]> > with(lt, ISOdate(1901+year, mon, mday, 0, tz = "")) > with(lt, ISOdate(1901+year, mon, mday, 23, 59, 59, tz = ""))+1 > > > > On 4/10/06, Omar Lakkis <uofiowa at gmail.com> wrote: > > I use POSIXct for datetimes. Is thee a timeAlign function that I can > > use where : > > > > align by year > > direction -1 ==> start of this year > > direction 1 ==> start of next year > > align by week > > direction -1 ==> date on last sunday > > direction 1 ==> date on next sunday > > align by day > > direction -1 ==> time at past midnight > > direction 1 ==> time at this comming midnight > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >
Are you looking for trunc.POSIXt? That does the -1 direction, and its code could easily be adapted (or just add one unit). I don't see what this has to do with 'align'. On Mon, 10 Apr 2006, Omar Lakkis wrote:> I use POSIXct for datetimes. Is thee a timeAlign function that I can > use where : > > align by year > direction -1 ==> start of this year > direction 1 ==> start of next year > align by week > direction -1 ==> date on last sunday > direction 1 ==> date on next sunday > align by day > direction -1 ==> time at past midnight > direction 1 ==> time at this comming midnight > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- 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