zoo

R: merge two irregular time series

落爺英雄遲暮 提交于 2019-11-27 07:01:01
I have two multivariate time series x and y, both covering approximately the same range in time (one starts two years before the other, but they end on the same date). Both series have missing observations in the form of empty columns next to the date column, and also in the sense that one of the series has several dates that are not found in the other, and vice versa. I would like to create a data frame (or similar) with a column that lists all the dates found in x OR y, without duplicate dates. For each date (row), I would like to horizontally stack the observations from x next to the

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

Moving average of previous three values in R

纵饮孤独 提交于 2019-11-27 04:41:25
In the zoo package there is a function called rollmean, which enables you to make moving averages. The rollmean(x,3) will take the previous, current and next value (ie 4, 6 and 2) in the table below. This is shown in the second column. x rollmean ma3 4 6 4.0 2 4.3 5 3.0 4.0 2 6.3 4.3 12 6.0 3.0 4 6.0 6.3 2 6.0 I would like to get the same job done, but by averaging out the previous 3 values in the fourth row. This is displayed in the third column. Can anybody tell me the name of the function that will help to accomplish this? w_i_l_l I struggled searching for a simple function for moving

Is there a _fast_ way to run a rolling regression inside data.table?

不想你离开。 提交于 2019-11-27 04:33:47
I am running rolling regressions in R, using with the data stored in a data.table . I have a working version, however it feels like a hack -- I am really using what i know from the zoo package, and none of the magic in data.table ... thus, it feels slower than it ought to be. Incorporating Joshua's suggestion - below - there is a speedup of ~12x by using lm.fit rather than lm . (revised) Example code: require(zoo) require(data.table) require(rbenchmark) set.seed(1) tt <- seq(as.Date("2011-01-01"), as.Date("2012-01-01"), by="day") px <- rnorm(366, 95, 1) DT <- data.table(period=tt, pvec=px) dtt

Creating regular 15-minute time-series from irregular time-series

夙愿已清 提交于 2019-11-27 03:36:34
I have an irregular time-series (with DateTime and RainfallValue) in a csv file C:\SampleData.csv : DateTime,RainInches 1/6/2000 11:59,0 1/6/2000 23:59,0.01 1/7/2000 11:59,0 1/13/2000 23:59,0 1/14/2000 0:00,0 1/14/2000 23:59,0 4/14/2000 3:07,0.01 4/14/2000 3:12,0.03 4/14/2000 3:19,0.01 12/31/2001 22:44,0 12/31/2001 22:59,0.07 12/31/2001 23:14,0 12/31/2001 23:29,0 12/31/2001 23:44,0.01 12/31/2001 23:59,0.01 Note: The irregular time-steps could be 1 min, 15 min, 1 hour, etc. Also, there could be multiple observations in a desired 15-min interval. I am trying to create a regular 15-minute time

Access zoo or xts index

不羁岁月 提交于 2019-11-27 02:34:15
问题 I am using zoo objects, buy my question also applies to xts objects. It looks to me like it is a one column vector with an index. In my case the index is the vector of dates and the one column vector my data. All is good except that I would like to access the dates (from the index). For example I have the following result: ObjZoo <- structure(c(10, 20), .Dim = c(2L, 1L), index = c(14788, 14789), class = "zoo", .Dimnames = list(NULL, "Data")) unclass(ObjZoo) # Data # [1,] 10 # [2,] 20 # attr(,

redis学习

ε祈祈猫儿з 提交于 2019-11-27 02:24:38
redis学习 NoSQL 学名(not only sql) 特点: 存储结构与mysql这一种关系型数据库完全不同,nosql存储的是KV形式 nosql有很多产品,都有自己的api和语法,以及业务场景 产品种类: Mongodb redis Hbase hadoop Nosql和sql的区别 应用场景不同,sql支持关系复杂的数据查询,nosql反之 sql支持事务性,nosql不支持 redis特性 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件redis是c语言编写的,支持数据持久化,是key-value类型数据库。应用在缓存,队列系统中redis支持数据备份,也就是master-slave模式 redis优势 性能高,读取速度10万次每秒 写入速度8万次每秒 所有操作支持原子性用作缓存数据库,数据放在内存中替代某些场景下的mysql,如社交类app大型系统中,可以存储session信息,购物车订单 yum安装redis 1.yum安装 #前提得配置好阿里云yum源,epel源 #查看是否有redis包 yum list redis#安装redisyum install redis -y#安装好,启动redissystemctl start redis 2.检测redis是否工作 redis-cli #redis

rollmean with dplyr and magrittr

半城伤御伤魂 提交于 2019-11-27 02:21:04
问题 Given the following data: set.seed(1) data <- data.frame(o=c('a','a','a','a','b','b','b','b','c','c','c','c'), t=c(1,2,3,4,1,2,3,4,1,2,3,4), u=runif(12), v=runif(12)) data o t u v 1 a 1 0.26550866 0.6870228 2 a 2 0.37212390 0.3841037 3 a 3 0.57285336 0.7698414 4 a 4 0.90820779 0.4976992 5 b 1 0.20168193 0.7176185 6 b 2 0.89838968 0.9919061 7 b 3 0.94467527 0.3800352 8 b 4 0.66079779 0.7774452 9 c 1 0.62911404 0.9347052 10 c 2 0.06178627 0.2121425 11 c 3 0.20597457 0.6516738 12 c 4 0.17655675

Rolling window over irregular time series

不羁的心 提交于 2019-11-27 00:58:07
问题 I have an irregular time series of events (posts) using xts , and I want to calculate the number of events that occur over a rolling weekly window (or biweekly, or 3 day, etc). The data looks like this: postid 2010-08-04 22:28:07 867 2010-08-04 23:31:12 891 2010-08-04 23:58:05 901 2010-08-05 08:35:50 991 2010-08-05 13:28:02 1085 2010-08-05 14:14:47 1114 2010-08-05 14:21:46 1117 2010-08-05 15:46:24 1151 2010-08-05 16:25:29 1174 2010-08-05 23:19:29 1268 2010-08-06 12:15:42 1384 2010-08-06 15:22

calculating sum of previous 3 rows in R data.table (by grid-square)

房东的猫 提交于 2019-11-26 17:17:17
问题 I would like to calculate the rainfall that has fallen over the last three days for each grid square, and add this as a new column in my data.table. To be clear, I want to sum up the current and PREVIOUS two (2) days of rainfall, for each meterological grid square library ( zoo ) library (data.table) # making the data.table rain <- c(NA, NA, NA, 0, 0, 5, 1, 0, 3, 10) # rainfall values to work with square <- c(1,1,1,1,1,1,1,1,1,2) # the geographic grid square for the rainfall measurement