Re: [R] Constructing dummy variables for months for a time series object

From: N. Lapidus <n.lapidus_at_gmail.com>
Date: Fri, 25 Apr 2008 10:19:57 +0200

Oops.. the last line should have been :
for (NumMonth in 1:12) assign(NameDummy[NumMonth], GenDummyVar (NumMonth))

On Fri, Apr 25, 2008 at 10:18 AM, N. Lapidus <n.lapidus_at_gmail.com> wrote:

> > GenDummyVar <- function (NumMonth) rep(c(rep(0, NumMonth-1), 1, rep(0,
> 12-NumMonth)), 17)
> > NameDummy <- c("DJan", "DFeb", "DMar", "DApr", "DMay", "DJun", "DJul",
> "DAug", "DSep", "DOct", "DNov", "DDec")
> > for (NumMonth in 1:12) assign(NameDummy, GenDummyVar (NumMonth))
>
> > DJan
> [1] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
> 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
> [74] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
> 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0
> [147] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
> 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
> > DFeb
> [1] 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
> 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
> [74] 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
> 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
> [147] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
> 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
>
> Is this what you need ?
> Why 11 (and not 12) months ?
> Nael
>
>
>
> On Fri, Apr 25, 2008 at 9:40 AM, Megh Dal <megh700004_at_yahoo.com> wrote:
>
>> I have a TS of monthly observations.
>>
>> head(data4)
>> 1991(1) 1991(2) 1991(3) 1991(4) 1991(5) 1991(6)
>> 12.00864 11.94203 11.98386 12.01900 12.19226 12.15488
>>
>> Now I want to make 11 dummy variables indicating months. Therefore I did
>> followings :
>>
>> For Jan :
>> rep(c(rep(0,0), 1, rep(0, 11)), 17)
>>
>> For Feb :
>> rep(c(rep(0,1), 1, rep(0, 10)), 17)
>>
>> ........ and so on
>>
>> But my question is there any way to aumate this? Or I have to do the
>> above thing for all 11 months?
>>
>>
>> ---------------------------------
>> [[elided Yahoo spam]]
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org 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.
>>
>
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Fri 25 Apr 2008 - 08:24:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Apr 2008 - 09:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive