Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • seq improperly increments dates (PR#9120)

    5 answers - 2527 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    You're right, it's tricky.
    I guess I would expect Jan. 30 + 1 month = Feb. 28.
    couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    I understand.
    Being that "1 month" is imprecise in terms of number of days,
    this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    in my opinion.
    That is what I expected, anyway.
    Thanks,
    Stephen
    Message
    From: Duncan Murdoch [mailto:murdoch (AT) stats (DOT) uwo.ca]
    Sent: Thursday, August 03, 2006 11:24 AM
    To: Ponzio, Stephen [CIB-LAVA]
    Cc: r-devel (AT) stat (DOT) math.ethz.ch; R-bugs (AT) biostat (DOT) ku.dk
    Subject: Re: [Rd] seq improperly increments dates (PR#9120)
    8/3/2006 10:26 AM, stephen.ponzio (AT) citigroup (DOT) com wrote:
    Full_Name: Stephen Ponzio
    Version: 2.3.1
    S: Windows
    Submission from: (NULL) (199.67.138.42)
    With the option by="1 month" and a date that is the 31st,
    the function seq doesn't give the last day of successive months,
    as I would expect it should:
    Why would you expect that? I'd expect it to give the day 30 days after
    the 1st, and that appears to be what it does. This doesn't look like a
    bug to me.
    I don't understand what logic you would like it to use. If I ask to
    increment Jan 30 in a non-leap-year by one month, should I get March 2
    (29 days after the 1st of January, as now), February 27 (the day before
    the end of the month), or February 28 (the closest you can get in February)?
    Whatever you choose, you'll get anomalies. Currently it skips months in
    sequences like you show below. If you try for the same distance from
    the end of the month each time, or truncate to the end of a short month,
    you lose important arithmetic properties: x - y is not equal to
    (x+1month) - (y+1month).
    Duncan Murdoch

    >Sys.Date()

    [1] "2006-08-03"

    >Sys.Date()-3

    [1] "2006-07-31"
    # WRKS K on Aug. 1:
    >seq(Sys.Date()-2, len=5, by="1 month")

    [1] "2006-08-01" "2006-09-01" "2006-10-01" "2006-11-01" "2006-12-01"
    # DESN'T WRK on July 31 (list has no date in Sept):
    >seq(Sys.Date()-3, len=5, by="1 month")

    [1] "2006-07-31" "2006-08-31" "2006-10-01" "2006-10-31" "2006-12-01"
    R-devel (AT) r-project (DOT) org mailing list
    R-devel (AT) r-project (DOT) org mailing list
  • No.1 | | 3000 bytes | |

    That's, in fact, the way seq.dates works in the chron package:

    library(chron)
    x <- chron("01/31/2006")
    seq(x, by = "month", length = 2) # 01/31/06 02/28/06

    See the help desk article in R News 4/1 for more about the main
    date classes.

    8/3/06, Ponzio, Stephen [CIB-LAVA] <stephen.ponzio (AT) citigroup (DOT) comwrote:
    You're right, it's tricky.

    I guess I would expect Jan. 30 + 1 month = Feb. 28.

    couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    I understand.

    Being that "1 month" is imprecise in terms of number of days,
    this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    in my opinion.

    That is what I expected, anyway.

    Thanks,
    Stephen
    >
    >
    >

    Message
    From: Duncan Murdoch [mailto:murdoch (AT) stats (DOT) uwo.ca]
    Sent: Thursday, August 03, 2006 11:24 AM
    To: Ponzio, Stephen [CIB-LAVA]
    Cc: r-devel (AT) stat (DOT) math.ethz.ch; R-bugs (AT) biostat (DOT) ku.dk
    Subject: Re: [Rd] seq improperly increments dates (PR#9120)
    --
    8/3/2006 10:26 AM, stephen.ponzio (AT) citigroup (DOT) com wrote:
    Full_Name: Stephen Ponzio
    Version: 2.3.1
    S: Windows
    Submission from: (NULL) (199.67.138.42)
    --
    With the option by="1 month" and a date that is the 31st,
    the function seq doesn't give the last day of successive months,
    as I would expect it should:

    Why would you expect that? I'd expect it to give the day 30 days after
    the 1st, and that appears to be what it does. This doesn't look like a
    bug to me.

    I don't understand what logic you would like it to use. If I ask to
    increment Jan 30 in a non-leap-year by one month, should I get March 2
    (29 days after the 1st of January, as now), February 27 (the day before
    the end of the month), or February 28 (the closest you can get in February)?

    Whatever you choose, you'll get anomalies. Currently it skips months in
    sequences like you show below. If you try for the same distance from
    the end of the month each time, or truncate to the end of a short month,
    you lose important arithmetic properties: x - y is not equal to
    (x+1month) - (y+1month).

    Duncan Murdoch
    >
    >
    >Sys.Date()

    [1] "2006-08-03"
    >
    >Sys.Date()-3

    [1] "2006-07-31"

    # WRKS K on Aug. 1:
    >seq(Sys.Date()-2, len=5, by="1 month")

    [1] "2006-08-01" "2006-09-01" "2006-10-01" "2006-11-01" "2006-12-01"

    # DESN'T WRK on July 31 (list has no date in Sept):
    >seq(Sys.Date()-3, len=5, by="1 month")

    [1] "2006-07-31" "2006-08-31" "2006-10-01" "2006-10-31" "2006-12-01"

    R-devel (AT) r-project (DOT) org mailing list

    R-devel (AT) r-project (DOT) org mailing list

    R-devel (AT) r-project (DOT) org mailing list
  • No.2 | | 2049 bytes | |

    "Gabor" == Gabor Grothendieck <ggrothendieck (AT) gmail (DOT) com>
    on Thu, 3 Aug 2006 20:14:24 -0400 writes:

    GaborThat's, in fact, the way seq.dates works in the chron package:
    Gaborlibrary(chron)
    Gaborx <- chron("01/31/2006")
    Gaborseq(x, by = "month", length = 2) # 01/31/06 02/28/06

    Hmm, so, by "logic",
    2006-01-31 + 1month |-2006-02-28
    2006-01-30 + 1month |-2006-02-27 (?)
    2006-01-29 + 1month |-2006-02-26 (?)
    2006-01-28 + 1month |-2006-02-25 ??

    I really don't like 'chron's behavior which seems much less
    logical to me than what R does with the official "Date" objects :

    options(width=88)
    for(d in 28:31) print(seq(as.Date(paste("2006-01", d, sep="-")), len = 6, by="1 month"))
    [1] "2006-01-28" "2006-02-28" "2006-03-28" "2006-04-28" "2006-05-28" "2006-06-28"
    [1] "2006-01-29" "2006-03-01" "2006-03-29" "2006-04-29" "2006-05-29" "2006-06-29"
    [1] "2006-01-30" "2006-03-02" "2006-03-30" "2006-04-30" "2006-05-30" "2006-06-30"
    [1] "2006-01-31" "2006-03-03" "2006-03-31" "2006-05-01" "2006-05-31" "2006-07-01"

    {which, BTW, *is* reproducible code; the bug report was only
    reproducible on the day it was posted because it sillily used
    Sys.date()}

    GaborSee the help desk article in R News 4/1 for more about the main
    Gabordate classes.

    Gabor8/3/06, Ponzio, Stephen [CIB-LAVA] <stephen.ponzio (AT) citigroup (DOT) comwrote:
    >You're right, it's tricky.
    >
    >I guess I would expect Jan. 30 + 1 month = Feb. 28.
    >
    >couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    >I understand.
    >
    >Being that "1 month" is imprecise in terms of number of days,
    >this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    >in my opinion.
    >
    >That is what I expected, anyway.
    >
    >Thanks,
    >Stephen


    []

    R-devel (AT) r-project (DOT) org mailing list
  • No.3 | | 3194 bytes | |

    Here are some more seq.dates examples from chron.
    It seems that if seq.Date cannot output day of the month n
    (because the month has fewer days) then it outputs n days from
    the start of the month even if that goes into the next month
    whereas seq.dates in chron outputs the end of the month in that case.

    library(chron)
    seq(chron("01/31/2006"), by = "month", length = 6)
    [1] 01/31/06 02/28/06 03/31/06 04/30/06 05/31/06 06/30/06

    seq(chron("01/30/2006"), by = "month", length = 6)
    [1] 01/30/06 02/28/06 03/30/06 04/30/06 05/30/06 06/30/06

    seq(chron("01/29/2006"), by = "month", length = 6)
    [1] 01/29/06 02/28/06 03/29/06 04/29/06 05/29/06 06/29/06

    seq(chron("01/28/2006"), by = "month", length = 6)
    [1] 01/28/06 02/28/06 03/28/06 04/28/06 05/28/06 06/28/06

    seq(chron("01/27/2006"), by = "month", length = 6)
    [1] 01/27/06 02/27/06 03/27/06 04/27/06 05/27/06 06/27/06

    8/4/06, Martin Maechler <maechler (AT) stat (DOT) math.ethz.chwrote:
    "Gabor" == Gabor Grothendieck <ggrothendieck (AT) gmail (DOT) com>
    on Thu, 3 Aug 2006 20:14:24 -0400 writes:

    GaborThat's, in fact, the way seq.dates works in the chron package:
    Gaborlibrary(chron)
    Gaborx <- chron("01/31/2006")
    Gaborseq(x, by = "month", length = 2) # 01/31/06 02/28/06

    Hmm, so, by "logic",
    2006-01-31 + 1month |-2006-02-28
    2006-01-30 + 1month |-2006-02-27 (?)
    2006-01-29 + 1month |-2006-02-26 (?)
    2006-01-28 + 1month |-2006-02-25 ??

    I really don't like 'chron's behavior which seems much less
    logical to me than what R does with the official "Date" objects :

    options(width=88)
    for(d in 28:31) print(seq(as.Date(paste("2006-01", d, sep="-")), len = 6, by="1 month"))
    [1] "2006-01-28" "2006-02-28" "2006-03-28" "2006-04-28" "2006-05-28" "2006-06-28"
    [1] "2006-01-29" "2006-03-01" "2006-03-29" "2006-04-29" "2006-05-29" "2006-06-29"
    [1] "2006-01-30" "2006-03-02" "2006-03-30" "2006-04-30" "2006-05-30" "2006-06-30"
    [1] "2006-01-31" "2006-03-03" "2006-03-31" "2006-05-01" "2006-05-31" "2006-07-01"
    --
    {which, BTW, *is* reproducible code; the bug report was only
    reproducible on the day it was posted because it sillily used
    Sys.date()}

    GaborSee the help desk article in R News 4/1 for more about the main
    Gabordate classes.

    Gabor8/3/06, Ponzio, Stephen [CIB-LAVA] <stephen.ponzio (AT) citigroup (DOT) comwrote:
    >You're right, it's tricky.
    >>

    >I guess I would expect Jan. 30 + 1 month = Feb. 28.
    >>

    >couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    >I understand.
    >>

    >Being that "1 month" is imprecise in terms of number of days,
    >this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    >in my opinion.
    >>

    >That is what I expected, anyway.
    >>

    >Thanks,
    >Stephen
    >

    []

    R-devel (AT) r-project (DOT) org mailing list
  • No.4 | | 2492 bytes | |

    8/4/2006 4:18 AM, Martin Maechler wrote:
    "Gabor" == Gabor Grothendieck <ggrothendieck (AT) gmail (DOT) com>
    on Thu, 3 Aug 2006 20:14:24 -0400 writes:

    GaborThat's, in fact, the way seq.dates works in the chron package:
    Gaborlibrary(chron)
    Gaborx <- chron("01/31/2006")
    Gaborseq(x, by = "month", length = 2) # 01/31/06 02/28/06

    Hmm, so, by "logic",
    2006-01-31 + 1month |-2006-02-28
    2006-01-30 + 1month |-2006-02-27 (?)
    2006-01-29 + 1month |-2006-02-26 (?)
    2006-01-28 + 1month |-2006-02-25 ??

    I really don't like 'chron's behavior which seems much less
    logical to me than what R does with the official "Date" objects :

    >options(width=88)
    >for(d in 28:31) print(seq(as.Date(paste("2006-01", d, sep="-")), len = 6, by="1 month"))

    [1] "2006-01-28" "2006-02-28" "2006-03-28" "2006-04-28" "2006-05-28" "2006-06-28"
    [1] "2006-01-29" "2006-03-01" "2006-03-29" "2006-04-29" "2006-05-29" "2006-06-29"
    [1] "2006-01-30" "2006-03-02" "2006-03-30" "2006-04-30" "2006-05-30" "2006-06-30"
    [1] "2006-01-31" "2006-03-03" "2006-03-31" "2006-05-01" "2006-05-31" "2006-07-01"

    {which, BTW, *is* reproducible code; the bug report was only
    reproducible on the day it was posted because it sillily used
    Sys.date()}

    I think the obvious solution here is to ask R Core to move the earth
    slightly closer to the sun, so the year is exactly 360 days long, and
    these problems don't arise.

    perhaps exactly 372 days would be better; that would be further from
    the sun and would also help with global warming.

    Duncan Murdoch

    GaborSee the help desk article in R News 4/1 for more about the main
    Gabordate classes.

    Gabor8/3/06, Ponzio, Stephen [CIB-LAVA] <stephen.ponzio (AT) citigroup (DOT) comwrote:
    >You're right, it's tricky.
    >
    >I guess I would expect Jan. 30 + 1 month = Feb. 28.
    >
    >couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    >I understand.
    >
    >Being that "1 month" is imprecise in terms of number of days,
    >this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    >in my opinion.
    >
    >That is what I expected, anyway.
    >
    >Thanks,
    >Stephen


    []

    R-devel (AT) r-project (DOT) org mailing list

    R-devel (AT) r-project (DOT) org mailing list
  • No.5 | | 3147 bytes | |

    Duncan Murdoch wrote:
    8/4/2006 4:18 AM, Martin Maechler wrote:
    "Gabor" == Gabor Grothendieck <ggrothendieck (AT) gmail (DOT) com>
    on Thu, 3 Aug 2006 20:14:24 -0400 writes:
    >GaborThat's, in fact, the way seq.dates works in the chron package:
    >Gaborlibrary(chron)
    >Gaborx <- chron("01/31/2006")
    >Gaborseq(x, by = "month", length = 2) # 01/31/06 02/28/06
    >>

    >Hmm, so, by "logic",
    >2006-01-31 + 1month |-2006-02-28
    >2006-01-30 + 1month |-2006-02-27 (?)
    >2006-01-29 + 1month |-2006-02-26 (?)
    >2006-01-28 + 1month |-2006-02-25 ??
    >>

    >I really don't like 'chron's behavior which seems much less
    >logical to me than what R does with the official "Date" objects :
    >>

    options(width=88)
    for(d in 28:31) print(seq(as.Date(paste("2006-01", d, sep="-")), len = 6, by="1 month"))
    >[1] "2006-01-28" "2006-02-28" "2006-03-28" "2006-04-28" "2006-05-28" "2006-06-28"
    >[1] "2006-01-29" "2006-03-01" "2006-03-29" "2006-04-29" "2006-05-29" "2006-06-29"
    >[1] "2006-01-30" "2006-03-02" "2006-03-30" "2006-04-30" "2006-05-30" "2006-06-30"
    >[1] "2006-01-31" "2006-03-03" "2006-03-31" "2006-05-01" "2006-05-31" "2006-07-01"
    >>

    >{which, BTW, *is* reproducible code; the bug report was only
    >reproducible on the day it was posted because it sillily used
    >Sys.date()}


    I think the obvious solution here is to ask R Core to move the earth
    slightly closer to the sun, so the year is exactly 360 days long, and
    these problems don't arise.

    perhaps exactly 372 days would be better; that would be further from
    the sun and would also help with global warming.

    Duncan Murdoch

    I am afraid that moving the earty so far out to induce an ice age, so
    I would please ask R-core to leave the earth alone!

    Kjetil


    >GaborSee the help desk article in R News 4/1 for more about the main
    >Gabordate classes.
    >>

    >Gabor8/3/06, Ponzio, Stephen [CIB-LAVA] <stephen.ponzio (AT) citigroup (DOT) comwrote:
    >>You're right, it's tricky.
    >>
    >>I guess I would expect Jan. 30 + 1 month = Feb. 28.
    >>
    >>couse, then Jan. 30 + 1 month = Jan. 28 + 1 month;
    >>I understand.
    >>
    >>Being that "1 month" is imprecise in terms of number of days,
    >>this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
    >>in my opinion.
    >>
    >>That is what I expected, anyway.
    >>
    >>Thanks,
    >>Stephen
    >>

    >[]
    >>

    >
    >R-devel (AT) r-project (DOT) org mailing list
    >


    R-devel (AT) r-project (DOT) org mailing list

    R-devel (AT) r-project (DOT) org mailing list

Re: seq improperly increments dates (PR#9120)


max 4000 letters.
Your nickname that display:
In order to stop the spam: 4 + 3 =
QUESTION ON "Development"

EMSDN.COM