zoo

Compute a rolling weighted sum by group

梦想的初衷 提交于 2020-01-20 08:59:10
问题 I have a working example of a weighted sum of transactions over the last 12 hours. Now, I've added an account column and would like to compute this weighted sum separately by group. The code will run as written below. Uncomment the line starting with # account to add the account column to df . How can I modify the second to last line of code such that it computes rollapplyr separately on each account ? library(zoo) library(tidyverse) Create the example data: set.seed(123) randomDates <-

Using “rollmedian” function as a input for “arima” function

核能气质少年 提交于 2020-01-15 10:55:07
问题 My time-series data includes date-time and temperature columns as follows: rn25_29_o: ambtemp dt 1 -1.96 2007-09-28 23:55:00 2 -2.02 2007-09-28 23:57:00 3 -1.92 2007-09-28 23:59:00 4 -1.64 2007-09-29 00:01:00 5 -1.76 2007-09-29 00:03:00 6 -1.83 2007-09-29 00:05:00 I am using median smoothing function to enhance small fluctuations that are caused because of imprecise measurements. unique_timeStamp <- make.time.unique(rn25_29_o$dt) temp.zoo<-zoo(rn25_29_o$ambtemp,unique_timeStamp) m.av<

Creating xts time series

瘦欲@ 提交于 2020-01-14 06:54:06
问题 zz <- textConnection("strtimestamp, jstimestamp, 61757, 61754, 61760, 61753, 61758, 61762, 61756, 61759, 61761, 61755, 61752 '01/01/2007 00:00:00', 1167606000000, 1145.3, 1647.3, 612, 963.3, 1063.5, 2294.3, 726.9, 280.8, 5182.4, 739.5, 1631.7 '01/01/2007 00:05:00', 1167606300000, 1116.7, 1625.4, 695.3, 948.4, 1111.8, 2262, 736.5, 202.7, 5135.8, 733, 1608.1 '01/01/2007 00:10:00', 1167606600000, 1100.3, 1613.4, 614.9, 957.5, 1059.8, 2261.6, 723.2, 238.5, 5114.5, 733, 1599.1 '01/01/2007 00:13:41

Clueless about this error: wrong sign in 'by' argument

余生颓废 提交于 2020-01-14 03:43:08
问题 I have the following dataset: >k1[1:10,] id web_name first_name second_name position date team1 team2 game_week points home_away team_scored team_conceded minutes goals assists 1 1 Fabianski Lukasz Fabianski Goalkeeper 17/08/13 ARS AVL 1 0 H 1 3 0 0 0 2 1 Fabianski Lukasz Fabianski Goalkeeper 24/08/13 ARS FUL 2 0 A 3 1 0 0 0 3 1 Fabianski Lukasz Fabianski Goalkeeper 01/09/13 ARS TOT 3 0 H 1 0 0 0 0 4 1 Fabianski Lukasz Fabianski Goalkeeper 14/09/13 ARS SUN 4 0 A 3 1 0 0 0 5 1 Fabianski Lukasz

R use apply function on xts zoo class

狂风中的少年 提交于 2020-01-11 13:37:09
问题 I am new in R and I try to use apply function on the xts zoo class, however it shows error. I have a formula: ((2*Close-High-Low)/(High-Low)) * Volume Input: y <- getSymbols("0005.HK", auto.assign = FALSE, src = "yahoo") Error: y$II <- apply(y,2,function(x) (2Cl(x) - Hi(x) - Lo(x)) / ((Hi(x) - Lo(x)) * Vo(stk))) Error: unexpected symbol in "apply(y,2,function(x) (2Cl" and then I tried another one: Error: y$II <- apply(y,2,function(x) (2(x[,4]) - x[,2] - x[,3]) / (x[,2] - x[,3]) * x[,5]) Error

Java 接口理解

[亡魂溺海] 提交于 2020-01-08 23:20:21
学习Spring有一段时间了,对java也有了一点了解,最不能理解的就是接口, 即使是写了接口并实现了它,依然无法理解它到底有什么用?看了其他几篇博客,总结了一下自己的理解。 在JAVA编程语言中是一个抽象类型,是抽象方法的集合。一个类通过继承接口的方式,从而来继承接口的抽象方法。 先从一个通俗的解释看起 (原文: C# 接口《通俗解释》 ) 如果你的工作是一个修水管的,一天客户找上你让你帮装水管,但是有个要求,就是客户喜欢管子是三角形的。 你立马买了三角形的水管回来,在墙上弄个三角形的口子,客户付了钱,你很开心今天有了收入,如下图,很好: 但是好景不长,客户过了一个星期又来找,因为他觉得三角形不好看,要让你换成正方形的水管,你不得不换,因为顾客就是上帝。好吧,继续在墙上弄个正方形的口子,然后又换成正方形的管子来接上。好了,如下图:(但是可能觉得为什么一开始不说要正方形的?因为需求总在变化。。。) 你累得满头大汗,但是还是完成了。可惜不久,客户又来找你,因为他想换成椭圆形的管子了。虽然你很无奈,但是你还是不得不花了几个小时完成。如下图: 安装完成,这时你可能在考虑,为什么换不同形状的水管,我都要大动干戈一番呢?于是你想到一个好方法,那就是墙上设计一个固定的水管并且是圆形的,当客户喜欢什么形状的水管,那么我只需要把客户喜欢的水管的一头做成圆形的,这样,以后都不需要去动墙上的水管了

redis学习

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-08 20:45:18
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 客户端工具

sum only the negative values in a row from an xts-object

风流意气都作罢 提交于 2020-01-06 07:29:11
问题 I have an xts-object and I want to sum only the negative values in the first row. The code sum(test[test<0]) gives me the error Error in `[.xts`(test, test < 0) : 'i' or 'j' out of range but sum(test[1],na.rm=TRUE) works, but then I have the sum of all the values, not just the negative ones: [1] -0.9786889 Without giving an example of data yet, does anybody know why this simple code doesnt work? The dimension of the xts-object is > dim(test) is 216 39 . 回答1: There is a chance that this is

Change maxgap for number of times a value is carried forward

笑着哭i 提交于 2020-01-06 02:38:36
问题 I have a data frame similar to the following: library(data.table) test <- data.table(data.frame("value" = c(5,NA,8,NA,NA,8,6,NA,NA,10), "locf_N" = c(1,NA,1,NA,NA,1,2,NA,NA,2)) ) In this data frame I have a variable that indicates the times I could carry forward the last observation (locf_N). This is not a fixed number for all observations. I have tried to use the maxgap parameter in the na.locf function for this purpose but it is not actually what I am looking for. require(zoo) test[,value :=

R: splitting long zoo time series into calendar

半腔热情 提交于 2020-01-04 06:32:16
问题 I have a several-year length zoo object. This is a time series of daily quotes (first column : date, second column : quote) I wish to split this long time series into calendar year subsets, the ultimate goal being to plot those data in a single chart, the horizontal axis of which being one year-length. (I don't want to convert my source daily data into monthly ones or any other timestep ...). Thank you. 回答1: Here's one way library(quantmod) getSymbols("SPY", src='yahoo', from='2000-01-01', to