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

2008-04-25 Thread Megh Dal
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,

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

2008-04-25 Thread N. Lapidus
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

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

2008-04-25 Thread N. Lapidus
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 [EMAIL PROTECTED] wrote: GenDummyVar - function (NumMonth) rep(c(rep(0, NumMonth-1), 1, rep(0, 12-NumMonth)), 17) NameDummy -

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

2008-04-25 Thread Bill.Venables
To: [EMAIL PROTECTED] Subject: [R] Constructing dummy variables for months for a time series object 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

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

2008-04-25 Thread Gabor Grothendieck
First generate a factor and then calculate its model matrix: month. - factor(cycle(x), labels = month.abb) model.matrix(~ month.)[,-1] Actually you may not even need the dummy variables at all if your purpose is to do a regression. You can use the factor directly: lm(x ~ month.) By the way,