Difficult to guess why, but I reckon you should use ts() instead of
as.ts. Otherwise set the tsp-attribute correctly. Eg :
> x <- cumsum(1+round(rnorm(20),2))
> as.ts(x)
Time Series:
Start = 1
End = 20
Frequency = 1
[1] 0.87 3.51 4.08 4.20 3.25 4.63 6.30 6.89 9.28 9.93 10.19
9.97 10.20 11.51 11.52 11.53 12.97 14.04 17.02 18.47
> tseries <- ts(x,frequency=12,start=c(2004,3))
> tseries
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2004 0.87 3.51 4.08 4.20 3.25 4.63 6.30 6.89 9.28 9.93
2005 10.19 9.97 10.20 11.51 11.52 11.53 12.97 14.04 17.02 18.47
> tsp(x) <- c(2004+2/12,2005.75,12)
> as.ts(x)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2004 0.87 3.51 4.08 4.20 3.25 4.63 6.30 6.89 9.28 9.93
2005 10.19 9.97 10.20 11.51 11.52 11.53 12.97 14.04 17.02 18.47
See ?ts to get the options right. I suggest to use the function ts()
instead of assigning the tsp attribute.
)
Cheers
Joris
On Mon, Jul 5, 2010 at 9:35 AM, nuncio m <nuncio.m at gmail.com>
wrote:> Dear useRs,
> I am trying to construct a time series using as.ts function, surprisingly
> when I plot
> the data the x axis do not show the time in years, however if I use
> ts(data), time in years are shown in the
> x axis. ?Why such difference in the results of both the commands
> Thanks
> nuncio
>
>
> --
> Nuncio.M
> Research Scientist
> National Center for Antarctic and Ocean research
> Head land Sada
> Vasco da Gamma
> Goa-403804
>
> ? ? ? ?[[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.
>
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control
tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php