Displaying 20 results from an estimated 4000 matches similar to: "converting a ts object to an xts object"
2017 Oct 06
2
Time series: xts/zoo object at annual (yearly) frequency
Hi,
I'd like to make a time series at an annual frequency.
> a<-xts(x=c(2,4,5), order.by=c("1991","1992","1993"))
Error in xts(x = c(2, 4, 5), order.by = c("1991", "1992", "1993")) :
order.by requires an appropriate time-based object
> a<-xts(x=c(2,4,5), order.by=1991:1993)
Error in xts(x = c(2, 4, 5), order.by =
2011 Mar 17
3
date conversion
Dear R People:
I have a monthly time series which runs from January 1998 to December 2010.
When I use tsp I get the following:
> tsp(ibm$ts)
[1] 1998.000 2010.917 12.000
Is there an easy way to convert this to a seq.Date object, please?
I would like to have something to the effect of
1998/01/01 .... 2010/12/01
Thanks,
Erin
--
Erin Hodgess
Associate Professor
Department of Computer
2010 Apr 20
1
converting a zoo or an xts to a data frame
Dear R People:
I have the following code that I use to convert a monthly zoo object
to a data.frame, and it works perfectly:
library(tseries)
z <- get.hist.quote(instrument=inst1, start=start1,end=end1,
quote=quot1,comp = "m")
y <- as.ts(aggregate(z, as.yearmon, tail, 1))
y.df <- data.frame(y=y,time=time(y))
y.df$x <- ts(y.df[,1])
tsp(y.df$x) <-
2007 Jul 25
3
aggregate.ts
Consider the following scrap of code:
> x<- ts(1:50,start=c(1,11),freq=12)
> y <- aggregate(x,nfreq=4)
> c(y)
[1] 6 15 24 33 42 51 60 69 78 87 96 105 114 123 132 141
> y
Error in rep.int("", start.pad) : invalid number of copies in rep.int()
> tsp(y)
[1] 1.833333 5.583333 4.000000
So we can aggregate into quarters, but we cannot print it using
2007 Jul 25
3
aggregate.ts
Consider the following scrap of code:
> x<- ts(1:50,start=c(1,11),freq=12)
> y <- aggregate(x,nfreq=4)
> c(y)
[1] 6 15 24 33 42 51 60 69 78 87 96 105 114 123 132 141
> y
Error in rep.int("", start.pad) : invalid number of copies in rep.int()
> tsp(y)
[1] 1.833333 5.583333 4.000000
So we can aggregate into quarters, but we cannot print it using
2012 Nov 10
2
For loop question
I have this code:
IEF <- to.monthly(IEF, indexAt="endof")
SPY <- to.monthly(SPY, indexAt="endof")
I would like to use a for loop instead of separate entries,
so the only code that needs to be modified is the list
of symbols.
symbols <- c("IEF", "SPY")
for(symbol in symbols) {
symbol <- to.monthly(symbol, indexAt="endof")
}
This
2009 Jun 14
1
time function behavior for ts class objects
Hi all-
I am trying to use the time function for ts class objects and do not
understand the return value. I want to use it to set up a time trend in
arima fits. It does not seem to return a correct linear sequence that
matches the underlying time series. I am running:
R version 2.8.1 (2008-12-22).
For example:
R> ## create a time series
R> x <- rnorm(24)
R> (xts <-
2018 Jan 28
1
Plotting quarterly time series
Using Achim's d this also works to generate z where FUN is a function used
to transform the index column and format is also passed to FUN.
z <- read.zoo(d, index = "time", FUN = as.yearqtr, format = "Q%q %Y")
On Sun, Jan 28, 2018 at 4:53 PM, Achim Zeileis <Achim.Zeileis at uibk.ac.at> wrote:
> On Sun, 28 Jan 2018, phil at philipsmith.ca wrote:
>
>> I
2018 Jan 28
0
Plotting quarterly time series
On Sun, 28 Jan 2018, phil at philipsmith.ca wrote:
> I have a data set with quarterly time series for several variables. The
> time index is recorded in column 1 of the dataframe as a character
> vector "Q1 1961", "Q2 1961","Q3 1961", "Q4 1961", "Q1 1962", etc. I want
> to produce line plots with ggplot2, but it seems I need to
1997 Aug 25
0
R-alpha: ts problems
This message is in MIME format
--_=XFMail.1.1.p0.Linux:970825095458:252=_
Content-Type: text/plain; charset=us-ascii
Here is a patch which fixes some problems with time series functions.
Some examples of what goes wrong...
> x <- ts(rnorm(100),start=1,deltat=2)
> start(x)
Error in ts[1] : object is not subsettable
> end(x)
Error in ts[2] : object is not subsettable
> y <-
2011 Nov 02
1
kernapply.ts
I have a suggestion for kernapply for ts objects. When we choose the
option circular=F, the returned series don't have the correct dates. The
removed dates are all at the beginning instead of half at the beginning
and half at the end. It is particularly useful when we need to smooth
the series (or remove a trend using a filter) before estimating a model
(like in macroeconomics) or simply
1999 Jul 27
3
Preliminary version of ts package
There is now a preliminary version of a time series package in the R-devel
snapshots, and we would welcome feedback on it. It is based in part on the
packages bats (Martyn Plummer) and tseries (Adrian Trapletti) and in part
on code I had or have written. (Thanks for the contributions, Martyn and
Adrian!) Some of the existing ts code has been changed, for example to plot
multiple time series, so
2005 Jun 03
1
ts.intersect a multivariate and univariate ts
This seems like a FAQ, but I can't figure it out.
I have a mv ts object:
R > tsp(pg)
[1] 1982 2003 1
R > dim(pg)
[1] 22 12
and a univariate ts:
R > tsp(rw)
[1] 1690 1996 1
Yet, when I try to intersect them:
R > tsp(ts.intersect(rw, pg))
[1] 1982 2176 1
the process goes awry.
How to I get rw and pg to be one ts that runs from 1982 to 1996 and has 13
univariate time
2012 Feb 16
3
Converting ts into xts and subsetting
Greetings,
I would like to subset observations in a time series using xts, after
converting from ts to xts.
X=ts(1:100, frequency=12, start=c(1976))
X2=as.xts(X)
X2["1984"]
The output:
Feb 1984 98
Mar 1984 99
Apr 1984 100
What happened to January? The index is always one month off, with
X2["1976-01"] giving me Feb 1976. Should I set the time using something
else
2012 Apr 12
4
Definition of "lag" is opposite in ts and xts objects!
Example:
Will ts objects be obsolete or modified?
> a [,1]
1983 Q1 2.747365190
1983 Q2 2.791594762
1983 Q3 -0.009953715
1983 Q4 -0.015059485
1984 Q1 -1.190061246
1984 Q2 -0.553031799
1984 Q3 0.686874720
1984 Q4 0.953911035> lag(a,4) [,1]
1983 Q1 NA
1983 Q2 NA
1983 Q3 NA
1983 Q4 NA
1984 Q1 2.747365190
1984 Q2
2010 Jul 03
2
Change the frequency of a ts?
I'm trying to convert a column of a table into a ts object. The data is
monthly, so I want the ts frequency to be 12.
I did this ...
> filings.ts = as.ts(Filings.100K, frequency=12)
> filings.ts
Time Series:
Start = 1
End = 311
Frequency = 1
[1] 246.9336 305.6789 ... ...
> tsp(filings.ts)
[1] 1 311 1
> tsp(filings.ts) <- c(1,311,12)
Error in attr(x, "tsp")
2009 Jan 22
0
Confused about behavior of an S4 object containing a ts object
I posted the question below about a month ago but received no response.
I still have not been able to figure out what is happening.
I also noticed another oddity. When the data part of the object is a
multivariate time series, it doesn't show up in the structure, but it
can be treated as a multivariate time series. Is this a bug in str?
> setClass("tsExtended", representation =
2008 May 31
1
Representing 'Date' as 'Year - Quarter'
I have financial data on a a set of firms, with a quarterly period
(fundamental data). The data spans 10 years, and four quarters per
year. The present file (.csv) reads the Date columns as "200706" for
the second quarter of 2007; "199809" for the third quarter of 1997.
Is there a way I can convert it to something like "2007 Q2", "1998 Q3"?
I am aware of
2005 Jan 31
2
changing the time base in a ts
I'm probably apporaching this all wrong to start but....
Suppose I have a monthly time series and I want to compute the mean of
months 6,7, and 8. I want to plot the original time series and the
seasonal time series, one above the other. When I do that as below the
time series don't line up for reasons that are obvious. How can I
change the base of the seasonal time series so I can make
2007 Nov 24
1
patch proposal for plot.ts
Hi all.
Currently, if you try:
> lag.plot(1:10)
you get superposed labels '1' and '10'. Things go worse in more extreme cases:
x <- ts(1:10)
x1 <- lag(x, 4)
plot(x1, x)
This is due to a mistake in plot.ts. My suggestion is the following
really minimal patch to plot.ts:
@@ -530,7 +530,7 @@ plot.ts <-
text(xy, labels =