Within an R dataset, I have a date field called date_. (The dates are in the
format -MM-DD, e.g. 1995-12-01.)
How can I add or subtract 1 month from this date, to get 1996-01-01 or
1995-11-01.
-
[[alternative H
On Tue, 2005-10-11 at 16:26 -0700, t c wrote:
> Within an R dataset, I have a date field called date_. (The dates are
> in the format -MM-DD, e.g. 1995-12-01.)
> How can I add or subtract 1 month from this date, to get 1996-01-01 or
> 1995-11-01.
There might be an easier way to do this, but
s.
> -Original Message-
> From: Marc Schwartz [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 11, 2005 10:16 PM
> To: t c
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] adding 1 month to a date
>
>
> On Tue, 2005-10-11 at 16:26 -0700, t c wrote:
> > Withi
TED]
>> Sent: Tuesday, October 11, 2005 10:16 PM
>> To: t c
>> Cc: r-help@stat.math.ethz.ch
>> Subject: Re: [R] adding 1 month to a date
>>
>>
>> On Tue, 2005-10-11 at 16:26 -0700, t c wrote:
>>> Within an R dataset, I have a date field called date_.
>&
eneral, as a month is not generally of 30 days (including
> in your example).
>
> seq.Date is a good way to do this.
>
> >
> >
> >> -Original Message-
> >> From: Marc Schwartz [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, October 11, 2005
> > > where 30*24*3600 = 30 days expressed in seconds.
> > >
> > > Sorry, not in general, as a month is not generally of 30 days (including
> > > in your example).
> > >
> > > seq.Date is a good way to do this.
> > >
> > > >
&g
On Wed, 12 Oct 2005, Jim Porzak wrote:
> OTOH,
>
> > seq(as.Date("2004-01-31"), by = "month", length = 14)
> [1] "2004-01-31" "2004-03-02" "2004-03-31" "2004-05-01" "2004-05-31"
> [6] "2004-07-01" "2004-07-31" "2004-08-31" "2004-10-01" "2004-10-31"
> [11] "2004-12-01" "2004-12-31" "2005-01-
Thanks. How do I se thsi to calculate a new variable (e.g."data$next_month")
from an existing variable (e.g."Data$date_").
I tried : ,
but get the following error message: "Error in seq.Date(as.Date(data$date),
len = 2, by = "1 month") : 'from' must be of length 1"
Thanks.
Gabor Gro
Thanks. How do I use this to calculate a new variable (e.g."data$next_month")
from an existing variable (e.g."Data$date_").
I tried : ,
but get the following error message: "Error in seq.Date(as.Date(data$date),
len = 2, by = "1 month") : 'from' must be of length 1"
Thanks.
Gabor Gr
quot;1995-12-01 08:00:00",format="%Y-%m-%d %H:%M:%S") +
> > > > > 30*24*3600
> > > > > where 30*24*3600 = 30 days expressed in seconds.
> > > >
> > > > Sorry, not in general, as a month is not generally of 30 days (including
> >
Try this:
seq(as.Date("2005-01-15"), len = 2, by = "month")[2]
or here is another approach:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/61570.html
On 10/11/05, t c <[EMAIL PROTECTED]> wrote:
>
> Within an R dataset, I have a date field called "date_". (The dates are in
> the format "-
Try this. Note that mapply strips off the class which is why we
set up dd with the correct class and then just replaced the values.
# test data
d <- as.Date("2005-1-1") + seq(0,90,30)
# calculations, dd is the result
next.month <- function(x) seq(x, len = 2, by = "months")[2]
dd <- d
dd[] <- mapp
12 matches
Mail list logo