xts

Splitting irregular time series into regular monthly averages - R

爱⌒轻易说出口 提交于 2019-12-03 08:42:37
In order to establish seasonal effects on energy use, I need to align the energy use information that I have from a billing database with monthly temperatures. I'm working with a billing dataset that has bills of varying lengths and start and end dates, and I'd like to obtain the monthly average for each account within each month. For example, I have a billing database that has the following characteristics: acct amount begin end days 1 2242 11349 2009-10-06 2009-11-04 29 2 2242 12252 2009-11-04 2009-12-04 30 3 2242 21774 2009-12-04 2010-01-08 35 4 2242 18293 2010-01-08 2010-02-05 28 5 2243

Animate map in R with leaflet and xts

人盡茶涼 提交于 2019-12-03 08:41:53
I would like to build an animated map with a time cursor in R. I have time series (xts) that I would like to represent on map. library(xts) library(leaflet) date<-seq(as.POSIXct("2015-01-01"), as.POSIXct("2015-01-10"), by=86400) a<-xts(1:10,order.by=date) b<-xts(5:14,order.by=date) df = data.frame(Lat = 1:10, Long = rnorm(10),Id=letters[1:10]) leaflet() %>% addCircles(data = df,popup =df$Id) #popup =paste(df$Id, xts value) time cursor on the map Is there a way to do this with the leaflet package? I didn't try rmaps package yet. Thanks EDIT: https://github.com/skeate/Leaflet.timeline There is a

How do I match data frames by time intervals?

ぃ、小莉子 提交于 2019-12-03 08:24:52
This is a problem that comes up often when I am importing raw data from data loggers. A temperature logger is set to record temperature every ten minutes, and a separate gas logger is set to record gas used in the last ten minute interval. I want to combine the data from these two loggers into a single data frame for plotting and analysis, but the times are not exactly aligned. I want to have one row in the data frame for each ten minute period, with the datetime showing the beginning of the time period. The temperature logger data looks like: datetime temperature 2010-09-30 06:58:53 78.996

regressions with xts in R

人盡茶涼 提交于 2019-12-03 05:01:46
Is there a utility to run regressions using xts objects of the following type: lm(y ~ lab(x, 1) + lag(x, 2) + lag(x,3), data=as.data.frame(coredata(my_xts))) where my_xts is an xts object that contains an x and a y . The point of the question is is there a way to avoid doing a bunch of lags and merges to have a data.frame with all the lags? I think that the package dyn works for zoo objects so i would expect it to work the same way with xts but though there might be something updated. G. Grothendieck The dyn and dynlm packages can do that with zoo objects. In the case of dyn just write dyn$lm

R Subset XTS weekdays

有些话、适合烂在心里 提交于 2019-12-03 02:12:35
How do I subset an xts object to only include weekdays (Mon-Fri, with Saturday and Sunday excluded)? Here's what I'd do: library(xts) data(sample_matrix) sample.xts <- as.xts(sample_matrix, descr='my new xts object') x <- sample.xts['2007'] x[!weekdays(index(x)) %in% c("Saturday", "Sunday")] EDIT : Joshua Ulrich in comments points out a better solution using .indexwday() , one of a family of built-in accessor functions for extracting pieces of the index of xts class objects. Also, like Dirk Eddelbuettel's solution, the following should be locale-independent: x[.indexwday(x) %in% 1:5] By

What does useMethod mean here?

风格不统一 提交于 2019-12-03 01:36:01
One of the kool things about R is if I type the function name I get to see the implementation. But this one is confusing me, recursively: > library(xts) > align.time function (x, ...) { UseMethod("align.time") } <environment: namespace:xts> x is an XTS object, so doesn't that mean it will call the XTS align.time method... but that is what I'm looking at! (Typing xts::align.time gives exactly the same response.) The short answer is that you are looking for the function xts:::align.time.xts . The longer answer is that you can find which methods exist for align.time by calling methods : > methods

r two xts operations

纵饮孤独 提交于 2019-12-02 20:45:40
问题 Two hourly time series xts1 and xts2, xts1 has some missing times. xts1 time speed power 2010-01-01 00:00:00 0.1 1.1 2010-01-01 01:00:00 0.2 1.2 2010-01-01 05:00:00 0.2 1.2 ..... xts2 time speed power 2010-01-01 00:00:00 0.1 1.1 2010-01-01 01:00:00 0.2 1.2 2010-01-01 02:00:00 0.2 1.2 ..... When combine them into one file(get the average of speed, and sum the power based on the same timestamp), get non--conformable arrays error. The command used was: hourly.data.table = data.table (time = time

How to use Plot.xts with Block and Events lines with xtsExtra package?

假如想象 提交于 2019-12-02 20:08:22
问题 I am trying to plot time series graph with blocks as others did. See the link for more detail of the example: http://www.r-bloggers.com/plot-xts-is-wonderful/. Firstly, I installed all newest xts (ver:0.9.874) and xtsExtra (ver: 0.0.876) packages from R-Forge: https://r-forge.r-project.org/R/?group_id=118. Then I tried to load xtsExtra and it shows as follows: library(xtsExtra) Attaching package: ‘xtsExtra’ The following objects are masked from ‘package:xts’: addLegend, addSeries, plot.xts

r two xts operations

非 Y 不嫁゛ 提交于 2019-12-02 12:32:56
Two hourly time series xts1 and xts2, xts1 has some missing times. xts1 time speed power 2010-01-01 00:00:00 0.1 1.1 2010-01-01 01:00:00 0.2 1.2 2010-01-01 05:00:00 0.2 1.2 ..... xts2 time speed power 2010-01-01 00:00:00 0.1 1.1 2010-01-01 01:00:00 0.2 1.2 2010-01-01 02:00:00 0.2 1.2 ..... When combine them into one file(get the average of speed, and sum the power based on the same timestamp), get non--conformable arrays error. The command used was: hourly.data.table = data.table (time = time(xts1), meanspeed= (coredata(xts1$speed)+coredata(xts2$speed))/2, power= coredata(xts1$power)+coredata

Extracting nth day of monthly data in r

ⅰ亾dé卋堺 提交于 2019-12-02 09:42:37
问题 I'm facing a problem with making columns using loop. I have a xts dataset and it's second-by-second data. It's start from 2014-09-01 00:00:00 104.172 2014-09-01 00:00:01 104.170 2014-09-01 00:00:02 104.170 2014-09-01 00:00:03 104.170 2014-09-01 00:00:04 104.170 2014-09-01 00:00:05 104.170 and end up with 2014-09-30 03:59:43 109.312 2014-09-30 03:59:44 109.312 2014-09-30 03:59:45 109.312 2014-09-30 03:59:46 109.312 2014-09-30 03:59:47 109.312 2014-09-30 03:59:48 109.313 I would like to make