xts

Add missing xts/zoo data with linear interpolation in R

半城伤御伤魂 提交于 2019-11-27 16:38:29
问题 I do have problems with missing data, but I do not have NAs - otherwise would be easier to handle... My data looks like this: time, value 2012-11-30 10:28:00, 12.9 2012-11-30 10:29:00, 5.5 2012-11-30 10:30:00, 5.5 2012-11-30 10:31:00, 5.5 2012-11-30 10:32:00, 9 2012-11-30 10:35:00, 9 2012-11-30 10:36:00, 14.4 2012-11-30 10:38:00, 12.6 As you can see - there are missing some minute values - it is xts/zoo so I use as.POSIXct... to set the date as an index. How to add the missing timesteps to

What is an efficient method for partitioning and aggregating intervals from timestamped rows in a data frame?

最后都变了- 提交于 2019-11-27 14:13:56
From a data frame with timestamped rows (strptime results), what is the best method for aggregating statistics for intervals? Intervals could be an hour, a day, etc. There's the aggregate function, but that doesn't help with assigning each row to an interval. I'm planning on adding a column to the data frame that denotes interval and using that with aggregate , but if there's a better solution it'd be great to hear it. Thanks for any pointers! Example Data Five rows with timestamps divided into 15-minute intervals starting at 03:00. Interval 1 "2010-01-13 03:02:38 UTC" "2010-01-13 03:08:14 UTC

Use dygraph for R to plot xts time series by year only?

人盡茶涼 提交于 2019-11-27 14:12:00
问题 I am trying to use the new dygraphs for R library to plot winning times for men and women in the Boston Marathon each year. I've got a data frame of winning times by second, here's a portion of it: winners <- data.frame(year=1966:1971, mensec=c(8231, 8145, 8537, 8029, 7830, 8325), womensec=c(12100, 12437, 12600, 12166, 11107, 11310)) But I don't know how to create an xts object from this. I can create a regular time series from each column and graph each one using dygraph in a separate graph

Grouping every n minutes with dplyr

≯℡__Kan透↙ 提交于 2019-11-27 13:51:16
问题 I have a dataset containing 10 events occuring at a certain time on a given day, with corresponding value for each event: d1 <- data.frame(date = as.POSIXct(c("21/05/2010 19:59:37", "21/05/2010 08:40:30", "21/05/2010 09:21:00", "21/05/2010 22:29:50", "21/05/2010 11:27:34", "21/05/2010 18:25:14", "21/05/2010 15:16:01", "21/05/2010 09:41:53", "21/05/2010 15:01:29", "21/05/2010 09:02:06"), format ="%d/%m/%Y %H:%M:%S"), value = c(11313,42423,64645,643426,1313313,1313,3535,6476,11313,9875)) I want

Fill NA in a time series only to a limited number

梦想与她 提交于 2019-11-27 08:56:21
Is there a way we can fill NA s in a zoo or xts object with limited number of NA s forward. In other words like fill NA s up to 3 consecutive NA s, and then keep the NA s from the 4th value on until a valid number. Something like this. library(zoo) x <- zoo(1:20, Sys.Date() + 1:20) x[c(2:4, 6:10, 13:18)] <- NA x 2014-09-20 2014-09-21 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 1 NA NA NA 5 NA NA 2014-09-27 2014-09-28 2014-09-29 2014-09-30 2014-10-01 2014-10-02 2014-10-03 NA NA NA 11 12 NA NA 2014-10-04 2014-10-05 2014-10-06 2014-10-07 2014-10-08 2014-10-09 NA NA NA NA 19 20 Desired

Using rollmean when there are missing values (NA)

给你一囗甜甜゛ 提交于 2019-11-27 06:10:22
问题 I have a data set which has a couple of NA in it. I take a rolling mean and expect that when there is no NA in the window, the rolling mean should produce a number as opposed to NA , however, rollmeanr in zoo does not seem to do this. Example: require(zoo) z = zoo(cbind(a=0:10, b=c(NA,10:1), c=sample(1:11,11)), 1:11) rollmeanr(z, k=3, fill=NA) a b c 1 NA NA NA 2 NA NA NA 3 1 NA 3.333333 4 2 NA 4.666667 5 3 NA 4.000000 6 4 NA 6.333333 7 5 NA 7.000000 8 6 NA 9.333333 9 7 NA 8.333333 10 8 NA 8

Remove duplicate rows from xts object

自古美人都是妖i 提交于 2019-11-27 05:51:40
问题 I am having trouble deleting duplicated rows in an xts object. I have a R script that will download tick financial data of a currency and convert it to an xts object of OHLC format. The script also pulls new data every 15 minutes. The new data is downloaded from the first trade of today to the last recorded trade of today. The old previous data downloaded was stored in .Rdata format and called. Then the new data is added to the old data and it overwrites the old data in .Rdata format. Here is

Subset xts object by time of day

拜拜、爱过 提交于 2019-11-27 04:56:31
A simple question: I know how to subset time series in xts for years, months and days from the help: x['2000-05/2001'] and so on. But how can I subset my data by hours of the day? I would like to get all data between 07:00 am and 06:00 pm. I.e., I want to extract the data during business time - irrelevant of the day (I take care for weekends later on). Help has an example of the form: .parseISO8601('T08:30/T15:00') But this does not work in my case. Does anybody have a clue? If your xts object is called x then something like y <- x["T09:30/T11:00"] works for me to get a slice of the morning

How can I change XTS to data.frame and keep Index?

ε祈祈猫儿з 提交于 2019-11-27 04:15:33
问题 I have an XTS timeseries in R of the following format and am trying to do some processing, subsetting and re-arranging before exporting as a CSV for work in another program. head(master_1) S_1 2010-03-03 00:00:00 2.8520 2010-03-03 00:30:00 2.6945 2010-03-03 01:00:00 2.5685 2010-03-03 01:30:00 2.3800 2010-03-03 02:00:00 2.2225 2010-03-03 02:30:00 2.0650 and str(master_1) An ‘xts’ object from 2010-03-03 to 2010-05-25 08:30:00 containing: Data: num [1:4000, 1] 2.85 2.69 2.57 2.38 2.22 ... - attr

Pull nth Day of Month in XTS in R

余生长醉 提交于 2019-11-27 03:40:26
问题 My questions is closely related to the one asked here: Pull Return from first business day of the month from XTS object using R. Instead of extracting the first day of each month, I want to extract, say the 10th data point of each month. How can I do this? 回答1: Using the same example data from the question you've linked to, you can do some basic subsetting. Here's the sample data: library(xts) data(sample_matrix) x <- as.xts(sample_matrix) Here's the subsetting: x[format(index(x), "%d") ==