xts

Fixing dimnames(x) of xts objects in R via loop

坚强是说给别人听的谎言 提交于 2019-12-12 20:28:14
问题 Assume I have a list of variables (class:xts) in .GlobalEnv identified as follows: ABC.xyz DEF.xyz GHI.xyz These variables are generated via a function. At present, the "column headers" in each variable are nonsense from the output of the original function. I would like to rename the columns in each of these variables to the first three letters of the variable name, followed by a generic suffix; say: ".XXX" I have tried to write a quick loop that uses the function dimnames(x) to achieve this

Updating an XTS object

落爺英雄遲暮 提交于 2019-12-12 11:27:09
问题 I've been struggling to do something is probably horribly simple on R. What I am trying to do is to update a XTS object column using another XTS object. Let's say I have the following XTS object, named Object1: A B 2000-01-03 , 14, NA 2000-01-04 , NA, NA 2000-01-05 , 16, 100 2000-01-06 , NA, 200 And the following XTS object, named Object2: A 2000-01-05 , 160 2000-01-06 , 20 I am looking for a way to update Object1 with values from Object2, having the following result: A B 2000-01-03 , 14, NA

Coercing a POSIXct object to Date object

不打扰是莪最后的温柔 提交于 2019-12-12 11:18:43
问题 Reproducible code: # Loading quantmod library(quantmod) # Please, put in R this structure a <- structure(c(2.4, 2.35, 2.44, 2.44, 2.31, 2.32, 2.41, 2.43, 2.46, 2.42, 2.45, 2.39, 2.3, 2.41, 2.33, 2.37, 2.38, 2.4, 2.275, 2.235, -0.0300000000000002, -0.0499999999999998, 0.0899999999999999, 0, -0.13, 0.00999999999999979, 0.0900000000000003, 0.02, 0.0299999999999998, -0.04, 0.0300000000000002, -0.0600000000000001, -0.0900000000000003, 0.11, -0.0800000000000001, 0.04, 0.00999999999999979, 0.02, -0

R: Error in xts - order.by

北城以北 提交于 2019-12-12 11:08:07
问题 I am trying to (re)build a basic prediction model of the S&P 500 INDEX (data orignates from Yahoo finance) I ran into some difficulties with the "ordering" of my data set. During the build of data.model the following error occurs Error in xts(new.x, x.index) : NROW(x) must match length(order.by) After some research I realize that the problem is with the ordering, and it seems to lack ordering as is required for the underlying zoo package. Is there an elegant way to solve this issue?! Thanks

Forcing full weeks with apply.weekly()

狂风中的少年 提交于 2019-12-12 10:48:05
问题 I'm trying to figure out what xts (or zoo) uses as the time after doing an apply.period. Consider the following: > myTs = xts(1:10, as.Date(1:10, origin = '2012-12-1')) > apply.weekly(myTs, colSums) [,1] 2012-12-02 1 2012-12-09 35 2012-12-11 19 I think the '2012-12-02' means "for the week ending 2012-12-02, the sum is 1". So basically the time is the end of the week. But the problem is with that "2012-12-11" - I think what it's doing is saying that the 11th is the last day of the week that

Convert epoch time dataframe with index as epoch time to xts object as accepted by ts object for forecasting

旧街凉风 提交于 2019-12-12 06:44:21
问题 I have a dataframe in R of the form: y 1484337600 19.22819 1484341200 19.28906 1484344800 19.28228 1484348400 19.21669 1484352000 19.32759 1484355600 19.21833 1484359200 19.20626 1484362800 19.28737 1484366400 19.20651 1484370000 19.18424 It has epoch times and values. Epoch times are row.names in this dataframe. Now, I want to convert this dataframe into ts() as understood by ARIMA. So, what I figured out now is ; I should convert this dataframe zoo or xts so that my epoch times are

Quotation marks when zoo to xts using as.xts() in R

淺唱寂寞╮ 提交于 2019-12-12 05:47:49
问题 When transforming the below data (class "zoo") into xts, I use returns.xts<-as.xts(returns) . The effect is to add quotation marks around the new Data. And then becomes unusable in functions. Why is this? class("zoo") UK.EQUITY EUR.EQUITY NA.EQUITY ASIA.EQUITY JPN.EQUITY EM.EQUITY WORLD.EQUITY.EX.UK 2006-04-30 0.010552982 -0.003337229 -0.033739353 0.025092643 -0.020920633 0.020016007 -0.021165353 2006-05-31 -0.048962517 -0.071924029 -0.059684763 -0.102475485 -0.098121902 -0.141877111 -0

Split time-series weekly in R

狂风中的少年 提交于 2019-12-12 03:45:47
问题 I want to split xts/zoo time-series in R on weekly basis. The timezone is set to "Asia/Kolkata" Sys.setenv(TZ="Asia/Kolkata") library(xts) seqs<- seq(as.POSIXct("2016-01-01"),as.POSIXct("2016-01-30"), by = "30 mins") ob<- xts(data.frame(value=1:(length(seqs))),seqs) weekdata <- split(ob,f="weeks",k=1) The problem with this split is that each week data is offset by 5:30 hours as shown below > head(weekdata[[2]],2) value 2016-01-04 05:30:00 156 2016-01-04 06:00:00 157 > head(weekdata[[3]],2)

Having a lot of issues with time series objects in R

久未见 提交于 2019-12-12 03:26:11
问题 I am having an extraordinarily difficult time dealing with -any- time series objects of some budget data. The original data is 14,460 rows of payments on ~1800 contracts, where each row has a DD/MM/YYYY and Amount feature. There are 5296 days between 1/1/2000 and 12/31/2014, but only 3133 of these days actually had payments. The days are therefore irregularly spaced, with more than one contract payment showing up on some days, and zero payments on others. The main issue I'm having is the

How do I subset the last week for every month of a zoo object in R?

不问归期 提交于 2019-12-12 01:44:25
问题 I have a few years of daily price data as a zoo object. What's the best way to subset the last week of 'every' month in R? Here's how you can replicate it: set.seed(123) price <- rnorm(365) data <- cbind(seq(as.Date("2013-01-01"), by = "day", length.out = 365), price) zoodata <- zoo(data[,2], as.Date(data[,1])) I tried this option but it only returns the last week of the entire data set. do.call(rbind, lapply(split(zoodata, "months"), last, "1 week")) Resulting output is: 2013-12-30 2013-12