I have an ascii data set of monthly observation starting in Jan 1946 with a header. hstarts 57 65 95 103 103 97 94 . . . Which I read with the following code tab6.1<-ts(read.table(fname, header=TRUE),frequency=12,start=c(1946,1)) I would like to run a time series model with dummy variables for each month. If I had a variable which take values from 1 to 12 indicating the month I could use the factor() function to model the series. reg1<-lm(hstarts~ -1 + factor(months)) Is there a function that will extract the year and month from a ts data set? Thanks, Richard Saba
In your case months <- rep(1:12,len=length(tab6.1)) should work. --- Richard Saba <sabaric at charter.net> wrote:> I have an ascii data set of monthly observation > starting in Jan 1946 with a > header. > > hstarts > 57 > 65 > 95 > 103 > 103 > 97 > 94 > . > . > . > > Which I read with the following code > tab6.1<-ts(read.table(fname, > header=TRUE),frequency=12,start=c(1946,1)) > > I would like to run a time series model with dummy > variables for each month. > If I had a variable which take values from 1 to 12 > indicating the month I > could use the factor() function to model the series. > > reg1<-lm(hstarts~ -1 + factor(months)) > > Is there a function that will extract the year and > month from a ts data set? > > Thanks, > Richard Saba > > ______________________________________________ > 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. >
If x is your series cycle(x) gives the months and floor(time(x)) gives the years. On Nov 27, 2007 7:57 PM, Richard Saba <sabaric at charter.net> wrote:> I have an ascii data set of monthly observation starting in Jan 1946 with a > header. > > hstarts > 57 > 65 > 95 > 103 > 103 > 97 > 94 > . > . > . > > Which I read with the following code > tab6.1<-ts(read.table(fname, header=TRUE),frequency=12,start=c(1946,1)) > > I would like to run a time series model with dummy variables for each month. > If I had a variable which take values from 1 to 12 indicating the month I > could use the factor() function to model the series. > > reg1<-lm(hstarts~ -1 + factor(months)) > > Is there a function that will extract the year and month from a ts data set? > > Thanks, > Richard Saba > > ______________________________________________ > 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. >