On Thu, Oct 17, 2002 at 12:39:08PM -0700, Robert Schick wrote:> I have a data set of monthly river flows from 1960-2000, which are > similar in structure to the nottem data: > > > klam.flow > Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep > 1961 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 > 1962 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 > ... > > Which quickly led me to realize the data aren't a "ts" object, as it > plotted 40 stacked lines instead of one long series. I've tried > converting to this using ts or as.ts, e.g.looks like a data frame, then. You've got to R it's not a multivariate time series; R thinks it's one series for Oct, one for Nov, etc. So, convert to matrix, and you'll need to: 1) transpose it, so the *column* vectors are sequential in time (by default, when R unrolls a matrix to a vector, it stacks the columns, not the rows). 2) convert the matrix to a vector, so R knows it's univariate. 3) *then* convert to time series. whew. ;-) klam.ts <- ts(as.vector(t(klam.flow)),frequency=12,start=c(1961,10)) klam.ts Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1961 1461 1716 2524 1962 1773 1906 2005 1756 1575 1387 983 1094 1382 1907 2253 1985 1963 1907 1769 1676 2634 1386 929 766 968 1309 If that's wrong - i.e. each row in klam.flow is one year and the columns are just in a funny order - you'll have to juggle the columns before step 1 above. Like so:> klam.ts <- ts(as.vector(t(klam.flow[,c(4:12,1:3)])),frequency=12,start=c(1961,1)) > klam.tsJan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1961 1773 1906 2005 1756 1575 1387 983 1094 1382 1461 1716 2524 1962 1907 1769 1676 2634 1386 929 766 968 1309 1907 2253 1985 Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I have a data set of monthly river flows from 1960-2000, which are similar in structure to the nottem data:> klam.flowOct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep 1961 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 1962 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 ... I tried plotting with> ts.plot(klam.flow)Which quickly led me to realize the data aren't a "ts" object, as it plotted 40 stacked lines instead of one long series. I've tried converting to this using ts or as.ts, e.g.> klam.ts <- ts(data=klam.flow, start=1960,end=2000, frequency=12)But this seems to explode the number of time series, e.g.> klam.tsOct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Jan 1960 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 Feb 1960 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 Mar 1960 2511 2852 3661 2103 2189 2548 3841 2937 857 743 1058 1574 ... Any advice on how to properly create the ts object so it looks and plots a la Figure 13.15 in VR? I'm using R 1.60 on a Windows 2000 box. Thanks -- Rob Schick Research Associate NOAA Fisheries Santa Cruz Lab 110 Shaffer Road Santa Cruz, CA 95060 Phone: 831.420.3960 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Robert Schick wrote:> > I have a data set of monthly river flows from 1960-2000, which are > similar in structure to the nottem data: > > > klam.flow > Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep > 1961 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 > 1962 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 > ... > > I tried plotting with > > > ts.plot(klam.flow) > > Which quickly led me to realize the data aren't a "ts" object, as it > plotted 40 stacked lines instead of one long series. I've tried > converting to this using ts or as.ts, e.g. > > > klam.ts <- ts(data=klam.flow, start=1960,end=2000, frequency=12)If I understand your data correctly they start in October 1961? Then you should do something like R> klam.flow2 <- ts(as.vector(t(klam.flow)), start = c(1961, 10), freq 12) R> plot(klam.flow2) This turns your time series to one long vector first and then adds the "ts" properties. Z> But this seems to explode the number of time series, e.g. > > > klam.ts > Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep > Jan 1960 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 > Feb 1960 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 > Mar 1960 2511 2852 3661 2103 2189 2548 3841 2937 857 743 1058 1574 > ... > > Any advice on how to properly create the ts object so it looks and plots > a la Figure 13.15 in VR? > > I'm using R 1.60 on a Windows 2000 box. > > Thanks > -- > Rob Schick > Research Associate > NOAA Fisheries > Santa Cruz Lab > 110 Shaffer Road > Santa Cruz, CA 95060 > Phone: 831.420.3960 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Assuming what you are starting with is a matrix or dataframe, with months as column names and years as rownames, then ts(c(t(klam.flow)), start=c(1961, 10), freq=12) should work. Chris Turner |---------+------------------------------> | | | | | Robert.Schick at noaa.| | | gov | | | Sent by: | | | owner-r-help at stat.m| | | ath.ethz.ch | | | | | | | | | 10/17/02 03:39 PM | | | | |---------+------------------------------> >-------------------------------------------------------------------------------------------------------------------------------| | | | To: r-help-digest at stat.math.ethz.ch | | cc: | | Subject: [R] Newbie Time Series Questions | >-------------------------------------------------------------------------------------------------------------------------------| I have a data set of monthly river flows from 1960-2000, which are similar in structure to the nottem data:> klam.flowOct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep 1961 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 1962 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 ... I tried plotting with> ts.plot(klam.flow)Which quickly led me to realize the data aren't a "ts" object, as it plotted 40 stacked lines instead of one long series. I've tried converting to this using ts or as.ts, e.g.> klam.ts <- ts(data=klam.flow, start=1960,end=2000, frequency=12)But this seems to explode the number of time series, e.g.> klam.tsOct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Jan 1960 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 Feb 1960 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 Mar 1960 2511 2852 3661 2103 2189 2548 3841 2937 857 743 1058 1574 ... Any advice on how to properly create the ts object so it looks and plots a la Figure 13.15 in VR? I'm using R 1.60 on a Windows 2000 box. Thanks -- Rob Schick Research Associate NOAA Fisheries Santa Cruz Lab 110 Shaffer Road Santa Cruz, CA 95060 Phone: 831.420.3960 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._ This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of J.P. Morgan Chase & Co., its subsidiaries and affiliates. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 17 Oct 2002, Robert Schick wrote:> I have a data set of monthly river flows from 1960-2000, which are > similar in structure to the nottem data: > > > klam.flow > Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep > 1961 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 > 1962 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 > ...Is that starting in Oct 1961 or what?> I tried plotting with > > > ts.plot(klam.flow) > > Which quickly led me to realize the data aren't a "ts" object, as it > plotted 40 stacked lines instead of one long series. I've tried > converting to this using ts or as.ts, e.g. > > > klam.ts <- ts(data=klam.flow, start=1960,end=2000, frequency=12) > > But this seems to explode the number of time series, e.g. > > > klam.ts > Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep > Jan 1960 1461 1716 2524 1773 1906 2005 1756 1575 1387 983 1094 1382 > Feb 1960 1907 2253 1985 1907 1769 1676 2634 1386 929 766 968 1309 > Mar 1960 2511 2852 3661 2103 2189 2548 3841 2937 857 743 1058 1574I think you have a data frame or matrix. If a matrix, try klam.ts <- ts(as.vectior(t(klam.flow)), start=c(1961,10), frequency=12) If a data frame, try as.matrix and then the above.> Any advice on how to properly create the ts object so it looks and plots > a la Figure 13.15 in VR?The issue is to start with a `ts' object. The above may help, but your descriptions are not really consistent. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._