xts

How to remove a row from zoo/xts object, given a timestamp

白昼怎懂夜的黑 提交于 2019-12-06 01:44:47
问题 I was happily running with this code: z=lapply(filename_list, function(fname){ read.zoo(file=fname,header=TRUE,sep = ",",tz = "") }) xts( do.call(rbind,z) ) until Dirty Data came along with this at the end of one file: Open High Low Close Volume 2011-09-20 21:00:00 1.370105 1.370105 1.370105 1.370105 1 and this at the start of the next file: Open High Low Close Volume 2011-09-20 21:00:00 1.370105 1.371045 1.369685 1.3702 2230 So rbind.zoo complains about a duplicate. I can't use something

Removing NA columns in xts

走远了吗. 提交于 2019-12-06 00:50:16
问题 I have an xts in the following format a b c d e f ...... 2011-01-03 11.40 NA 23.12 0.23 123.11 NA ...... 2011-01-04 11.49 NA 23.15 1.11 111.11 NA ...... 2011-01-05 NA NA 23.11 1.23 142.32 NA ...... 2011-01-06 11.64 NA 39.01 NA 124.21 NA ...... 2011-01-07 13.84 NA 12.12 1.53 152.12 NA ...... Is there a function I can apply to generate a new xts or data.frame missing the columns containing only NA? The position of the columns with the NAs isn't static so just removing those columns by name or

R XTS to.minutes5(), is not converting as “I” expected

泄露秘密 提交于 2019-12-05 22:39:05
Hi i'm converting some 1 min data to 5 min data, and i'm finding it does 4 mins for the first increment, then goes on to do 5 min increments after that. I've tried messing around with all the "indexAt" parameters but none give me what i want, which is starting from 5, then 10, 15, 20 etc. i've tried x5 <- to.minutes5(x) AND x <- to.period(x, period = 'minutes', k = 5, OHLC = TRUE) 1 min data Open High Low Close Volume 2013-01-16 00:01:00 93.55 93.60 93.54 93.58 5 2013-01-16 00:02:00 93.59 93.60 93.58 93.58 5 2013-01-16 00:03:00 93.59 93.60 93.58 93.58 5 2013-01-16 00:04:00 93.58 93.58 93.57 93

endpoints in xts using R

房东的猫 提交于 2019-12-05 22:12:52
I am trying to figure out how endpoints selects the times when my data is only weakly regular: that is, some observations are missing. I have 1 minute returns with some minutes missing and I am trying to convert to 5 minute intervals. How will endpoints decide which times to keep? The call I use is: endpoints(ret_1_min_xts, k=5, "minutes") My series looks like this, for example: 1986-02-04 09:32:00 1 1986-02-04 09:33:00 2 1986-02-04 09:34:00 3 1986-02-04 09:35:00 4 1986-02-04 09:36:00 5 1986-02-04 09:37:00 6 1986-02-04 09:38:00 7 1986-02-04 09:39:00 8 1986-02-04 09:40:00 9 1986-02-04 09:41:00

matching time vectors of different length: a tricky one

别来无恙 提交于 2019-12-05 20:12:39
I have two sets of measurements from different machines. They are measured over time, at slightly different intervals - e.g. one makes a measurement every 5 mins, but the other, every 3 mins. The advantage is that the one every 5 mins is computed as an average over the whole interval so the values should correspond roughly to one another. I would like to expand the vector with measurements every 5 minutes (Light) so that its values are roughly synchronous with the values in vector of measurements made every 5 minutes. The gap should then be filled with the preceding value Here is an example of

How to make a set containing count of data in rolling set of buckets

雨燕双飞 提交于 2019-12-05 18:37:54
I have the server logs for a months worth of traffic. Partial example below "UploadDateGMT","UserFileSize","TotalBusinessUnits" "2012-01-01 00:00:38","1223","1" "2012-01-01 00:01:16","1302","1" "2012-01-01 00:08:10","1302","1" I would like to convert this into a data set where I have a count of how many bytes of submissions there were in each five minute window on a rolling basis. (i.e. 0-5, 1-6, 2-7, etc.) From this, I could extract maximum load, 95% load, make pretty graphs of load, etc. Joshua Ulrich To expand on @PLapointe's answer : endp <- endpoints(tab2, on="mins", k=1) # 1 minute

Error with xts::apply: “Error in coredata.xts(x) : currently unsupported data type”

二次信任 提交于 2019-12-05 18:24:31
The error occurred to me When I was trying to do the following work: # generate random integrals # data <- xts(floor(runif(100, 1,101)),as.Date("1973-02-01") + c(1:100) - 1) apply.monthly(data, diff,1,1) , while this one works: apply.monthly(data,mean) I have checked similar questions posted, but it seems they do not apply to the situation here. Any advice? Some further explanation: The reason I need this is that I got a time series data set like the following, 1990-05 100 1990-04 80 1990-03 60 1990-02 20 1990-01 5 1989-12 110 1989-11 89 1989-10 78 ... In each year, y(t)=y_(t-1)+dy , where dt

Extend a weekly times series into daily

无人久伴 提交于 2019-12-05 11:25:59
I have an xts time series of weekly values Jan 4 2004, 0.99 Jan 11 2004, 1.11 Jan 18 2004, 1.06 .... and I want to covert it to daily values Jan 4 2004, 0.99 Jan 5 2004, 0.99 Jan 6 2004, 0.99 .... Jan 10 2004, 0.99 Jan 11 2004, 1.11 Jan 12 2004, 1.11 Jan 13 2004, 1.11 .... where each value is replicated for the following 6 days. How can I do this in R? The data you show are not an xts series. I assume that is how the data are represented in a CSV file. To answer your question, I'm going to assume you have a weekly xts object, w . Merge w with an empty xts object with an index that spans all

Extracting the numerical values of a xts object

☆樱花仙子☆ 提交于 2019-12-05 04:10:29
I want to extract the numerical values of a xts object. Let's look at an example data <- new.env() starting.date <- as.Date("2006-01-01") nlookback <- 20 getSymbols("UBS", env = data, src = "yahoo", from = starting.date) Reg.curve <- rollapply(Cl(data$UBS), nlookback, mean, align="right") The Reg.cuve is still a xts object but actually I'm just interested in the running means. How can I modify Reg.curve to get a numerical vector? Use coredata : reg.curve.num <- coredata(Reg.curve) # or, if you want a vector: reg.curve.num <- drop(coredata(Reg.curve)) To extract the numerical values of any "xts

Optimize moving averages calculation - is it possible?

廉价感情. 提交于 2019-12-05 03:48:41
问题 Is it possible to optimize (make it much faster) this piece of code: out <- do.call(rbind, lapply(split(Cl(cumulativeBars), "days"), function(x) { previousFullBars <- barsEndptCl[as.Date(index(barsEndptCl), tz=indexTZ(barsEndptCl)) < as.Date(last(index(x)), tz=indexTZ(x)), ] if (NROW(previousFullBars) >= 4) { last(SMA(last(rbind(previousFullBars, x), n=6), n=5)) } else { xts(NA, order.by=index(x)) } })) Below you can find my original question with all the code example that runs but a bit to