Displaying 20 results from an estimated 4000 matches similar to: "Converting ts into xts and subsetting"
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
2012 Jun 10
1
Gaps on merging xts objects
Looking for a little help figuring out what's driving gaps in data after
merging two xts objects (msci.m and x2). The merge statement I'm using is
... y <-merge(x2,msci.m, all=FALSE). Here's info on the output , y:
head(y)
t-bill msci
Sep 1985 7.310 316.963
Mar 1986 6.560 463.471
Jun 1986 6.180 498.791
Jul 1987 6.200 778.898
Aug 1987 6.400 833.519
Nov 1987
2012 Oct 16
1
XTS Subsetting question (noob)
Hi,
How can an xts object be subset using a date in a variable?
E.g. in below, what is the right syntax for Q to get the same value as P?
Obviously the syntax shown below doesnt work...
V is an xts object.
d = "2007-01-01"
P <- V['2007-01-01/']
Q <- V['d/']
Thanks,
J
--
View this message in context:
2017 Sep 16
2
require help
You can just use the same code that I provided before but now use your
dataset. Like this
df <- read.csv(file="data2.csv",header=TRUE)
dates <- as.Date(paste(df$year,"-01-01",sep=""))
myXts <- xts(df,order.by=dates)
head(myXts)
#The last command "head(myXts)" shows you the first few rows of the xts
object
year cnsm incm wlth
2017 Sep 16
0
require help
oky.. thank you very much to all of you
On Sat, Sep 16, 2017 at 2:06 PM, Eric Berger <ericjberger at gmail.com> wrote:
> You can just use the same code that I provided before but now use your
> dataset. Like this
>
> df <- read.csv(file="data2.csv",header=TRUE)
> dates <- as.Date(paste(df$year,"-01-01",sep=""))
> myXts <-
2011 Jan 04
1
XTS : merge.xts seems to have problem with character vectors
Hi,
Please can you tell me what I am doing wrong. When trying to merge two xts
objects, one of which has multiple character vectors for columns...I am just
getting NAs.
> str(t)
POSIXct[1:1], format: "2011-01-04 11:45:37"
> y2 = xts(matrix(c(letters[1:10]),5), order.by=as.POSIXct(c(t + 1:5)))
> names(y2) = c(1,2)
> y2
1 2
2011-01-04 11:45:38
2017 Sep 22
2
require help
Assuming the input data.frame, DF, is of the form shown reproducibly
in the Note below, to convert the series to zoo or ts:
library(zoo)
# convert to zoo
z <- read.zoo(DF)
# convert to ts
as.ts(z) #
Note:
DF <- structure(list(year = c(1980, 1981, 1982, 1983, 1984), cnsm = c(174,
175, 175, 172, 173), incm = c(53.4, 53.7, 53.5, 53.2, 53.3),
with = c(60.3, 60.5, 60.2, 60.1, 60.7)),
2009 Nov 18
0
xts timeseries
Hi,
I try to calculate the correlation between macroeconomic data from
FRED vs Market Data
However, since the timeseries are not in synch, the correlation fails.
require(quantmod)
USPBS =get(getSymbols("USPBS", src="FRED" ))
USPBS = USPBS['1983-1-1::']
monDMANEMP = Cl(to.monthly(USPBS))
> length(monDMANEMP)
[1] 312
> head(monDMANEMP)
USPBS.Close
2012 Mar 04
1
Store vectors as values in xts time-series object
Hi R programmers,
I have stumbled across what seems a very simple problem. My goal is to
create a xts time series object which contains vectors as values. In
other words, I try to create something like this:
2009-01-01 => c('aa', 'bb', 'dd')
...
2010-02-01 => c('mm')
I have figured out parts of separately. Here's what works (new xts
time-series with
2017 Sep 16
0
require help
> On 15 Sep 2017, at 11:38, yadav neog <yadavneog at gmail.com> wrote:
>
> hello to all. I am working on macroeconomic data series of India, which in
> a yearly basis. I am unable to convert my data frame into time series.
> kindly help me.
> also using zoo and xts packages. but they take only monthly observations.
>
> 'data.frame': 30 obs. of 4 variables:
2015 Nov 04
1
setOldClass("xts")
Hello,
I apologize that I am cross posting here after getting no answer from
my initial
question on stack overflow
<http://stackoverflow.com/questions/33492601/r-setoldclass-only-if-needed>.
I should certainly have posted it first here..
I am using 3 packages:
- xts
- quantmod
- 'myPackage'
quantmod is creating a union class by doing:
setOldClass("xts");
2009 Nov 12
1
xts conversion problem
I have two data frames, with two columns each, the first being a Date
variable. I would like to convert them to xts objects, indexed by the
Date column. I would like to use as.Date and not as.POSIXct as the
dateformat. The puzzling fact is that it works for the first one but
not the other. Here is a screenshot of the error:
> str(DF1)
'data.frame': 367 obs. of 2 variables:
$
2011 Jul 30
1
Plot.xts - how to change the x-axis labels to show weekly labels.
Dear R-users
I am new to R and struggling not to bother the list with silly questions.
I read the documentation on xts and searched for some examples over the
internet on how to use plot.xts.
The xts object is as follows
dataxts : An 'xts' object from 2010-06-27 to 2010-08-05 containing:
Data: num [1:56161, 1:14] 74 74.2 74.2 74.1 73.9 ...
Indexed by objects of
2012 May 29
2
Converting to XTS loses data.frame structure
Hello,
I noticed something odd when working with data frames and xts objects.
If I read in a CSV file, R creates a nice data.frame. This works well.
If I then convert to an XTS object, I see that all the values in the data are now quoted. My data is a mix of numeric and character. This is usually seen when converting a data.frame to a matrix, as R will treat all the data as the same class.
2011 Nov 09
1
Are there equivalents to xblocks or rect that can be used with plot.xts?
I would like to add vertical shaded blocks in plot.xts graphs (like recession
periods in FRED graphs)
The reason I use plot.xts instead of plot.zoo is that I like the fact that
the grid is automatically aligned with major ticks in plot.xts.
xblocks() and rect() do not seem to work with plot.xts (only with plot.zoo).
Are there any alternative methods that work with plot.xts?
Thanks.
--
View
2010 Dec 06
1
as.xts error
Dear all,
I am using the as.xts function to transfer a data frame to the xts
The following is the code and result:
a<-read.csv("price.csv")
a$Date<-as.POSIXct(a$Date)
str(a)
'data.frame': 15637 obs. of 2 variables:
$ Date : POSIXct, format: "2010-01-04 09:45:01" "2010-01-04 09:45:02"
"2010-01-04 09:45:03" ...
$ bid_hsi: int 21850
2011 Dec 24
1
Optimising timeboxing in xts
I don't know if timeboxing is the correct term to use to accomplish
what I'm attempting, so allow me to explain. I have a set n of tagged
observations in time series t. What I'm interested in is taking i
seconds before and after every n. My code is below:
# observations.xts is an xts time series and arg is the number of
seconds to for the timebox
timeboxes <-
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 =
2012 Nov 30
1
xts indexed with Date class
Hi
I see a changed behaviour in xts indexed on class Date in the latest
versions, versus 2.
It seems to be related to changes to/from daylight savings time,
happens those weekends.
Is it not intended that class Date be used like this, or is this new
behaviour incorrect?
Giles
Example:
> a<-as.Date(15423:15426)
> x<-xts(seq_along(a),a)
> print(x)
[,1]
2012-03-24
2012 Nov 02
2
override date in xts time series
Using the following bit of R, I'm wondering if there is a way to
override/manipulate/replace the date in one xts time series with the date of
another xts time series while not affecting/changing the times of the xts
time series?
library(xts)
x.Date <- rep("1/1/2004",times=5)
x.Times<- c("00:00:00", "00:15:00", "00:30:00",