zoo

Is there any way to force zoo::rollmean function to return a vector that is the same length as it's input? (or maybe use other function?)

扶醉桌前 提交于 2019-12-05 19:39:49
input = cbind(c(3,7,3,5,2,9,1,4,6,4,7,3,7,4)) library(zoo) output = cbind(rollmean(input,4)) print(input) print(output) output: [,1] [1,] 3 [2,] 7 [3,] 3 [4,] 5 [5,] 2 [6,] 9 [7,] 1 [8,] 4 [9,] 6 [10,] 4 [11,] 7 [12,] 3 [13,] 7 [14,] 4 [,1] [1,] 4.50 [2,] 4.25 [3,] 4.75 [4,] 4.25 [5,] 4.00 [6,] 5.00 [7,] 3.75 [8,] 5.25 [9,] 5.00 [10,] 5.25 [11,] 5.25 but when I try to cbind it: Error in cbind(input, output) : number of rows of matrices must match (see arg 2) Calls: print -> cbind Execution halted I'd like to use a function that would be smart enough and do not give up if it doesn't get data on

dplyr mutate in zoo object

假如想象 提交于 2019-12-05 19:33:06
I was trying to apply the dplyr mutate in zoo object. But, it generated an error: Error in UseMethod("mutate") : no applicable method for 'mutate' applied to an object of class "zoo". I googled and saw that it has not been yet resolved. A recent discussion on this is here. I would appreciate if any one could help me in this regard. zoo has a transform method: library(zoo) z <- zoo(cbind(a = 1:3, b = 4:6)) transform(z, a = a + 1, c = a + b) giving: a b c 1 2 4 5 2 3 5 7 3 4 6 9 or using z from above, the following gives the same result: library(magrittr) z %>% transform(a = a + 1, c = a + b)

use rollapply and zoo to calculate rolling average of a column of variables

假如想象 提交于 2019-12-05 18:29:20
I want to calculate the rolling mean for all variables in column "sp". This is a sample of my data: the_date sp wins 01-06--2012 1 305 02-06--2012 1 276 03-06--2012 1 184 04-06--2012 1 248 05-06--2012 1 243 06-06--2012 1 363 07-06--2012 1 272 01-06--2012 2 432 02-06--2012 2 369 03-06--2012 2 302 04-06--2012 2 347 05-06--2012 2 357 06-06--2012 2 331 07-06--2012 2 380 01-06--2012 3 1 02-06--2012 3 2 03-06--2012 3 3 04-06--2012 3 2 05-06--2012 3 0 06-06--2012 3 2 07-06--2012 3 0 What I want, is to have a column added to data, that gives the moving average over 3 days for each sp. So the following

zookeeper

↘锁芯ラ 提交于 2019-12-05 14:29:39
Zookeeper是什么 官方文档上这么解释zookeeper,它是一个分布式服务框架,是Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。 上面的解释有点抽象,简单来说zookeeper=文件系统+监听通知机制。 1、 文件系统 Zookeeper维护一个类似文件系统的数据结构: 每个子目录项如 NameService 都被称作为 znode(目录节点),和文件系统一样,我们能够自由的增加、删除znode,在一个znode下增加、删除子znode,唯一的不同在于znode是可以存储数据的。 有四种类型的znode: PERSISTENT-持久化目录节点 客户端与zookeeper断开连接后,该节点依旧存在 PERSISTENT_SEQUENTIAL-持久化顺序编号目录节点 客户端与zookeeper断开连接后,该节点依旧存在,只是Zookeeper给该节点名称进行顺序编号 EPHEMERAL-临时目录节点 客户端与zookeeper断开连接后,该节点被删除 EPHEMERAL_SEQUENTIAL-临时顺序编号目录节点 客户端与zookeeper断开连接后,该节点被删除,只是Zookeeper给该节点名称进行顺序编号 2、 监听通知机制

rollapply time series in R (zoo) on backward looking data

廉价感情. 提交于 2019-12-05 14:27:43
I would like to use the zoo function rollapply to apply a function (for example mean) on a time series but only using the last N known points. For example: x = zoo(c(1,2,3,4), order.by=c(10,11,12,13)) rollmean(x,2) Produces: 10 11 12 1.5 2.5 3.5 I would like to produce a series that would have date entries of 11, 12, 13 and values of 1.5, 2.5, 3.5. The values seem correct but the dates that rollmean outputs don't seem to correspond to what I would like. I'm a bit worried about just assigning the dates I want to the zoo object using time(x)<- because I'm not sure that rollapply is actually

Can rollapply return a list of matrices?

隐身守侯 提交于 2019-12-05 10:33:35
I would like to generate covariance matrices (and mean vectors) using a rolling window. But in all my attempts rollapply stacks the covariance matrices from cov and runs out of pre-allocated space (e.g., if my original data have 40 observations, then rollapply can't return more than 40 rows). Is there a way that I can get rollapply to return a list of matrices? Or to return a data.frame that is larger than the original data.frame , which I can manually split into a list? My end goal is to take a panel, split the panel into a list of individual data.frame s, calculate the rolling covariances

python3中的集合

安稳与你 提交于 2019-12-05 06:35:40
集合(set)是一个无序的 不重复的 数据类型:   使用set()函数来创建集合,set([value])也可以使用 name = {age1,age2,age3...}来创建集合,但是创建空集合时需要使用set()来创建,一般情况下我们都是使用set()来创建集合。 #创建一个列表 #list1 = {"red","yellow","yellow","green"} 创建集合的方式1 #去重演示 >>>list2 = =set(["red","yellow","yellow","green"]) >>>print(list2) {'red', 'yellow', 'green'}#输出结果,因为集合是不重复的数据类型,所以这里的打印结果中不会有重复的元素 #判断元素是否在集合中 >>>"yellow" in list2#如果元素在列表中,返回True True >>>"blue" in list2 #否则返回为False False   下面展示两个集合数据的操作方式:aggregate1-aggregate2 = >>>a = set('abcabcabc')>>>b = set ('ccdefj') >>>print(a) {'b', 'c', 'a'}#去重之后的结果 >>>print(b){'c', 'f', 'e', 'j', 'd'}#同上 #"a-b

zookeeper集群启动报错:Cannot open channel to * at election address /ip:3888

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 05:43:51
下面几点需要注意的: 1、确认在每个$zookeeper_home/data/myid中有对应数字 2、是否关闭防火墙:systemctl stop firewalld,systemctl disable firewalld 3、zoo.cfg中的server需要写成以下形式的: 假如有两台机器,192.168.1.1和192.168.1.2,它们的myid分别是1和2; 192.168.1.1的zoo.cfg(其它属性的配置还按照原有的配置): server.1=0.0.0.0:2888:3888 server.2=192.168.1.2:2888:3888 192.168.1.2的zoo.cfg(其它属性的配置还按照原有的配置): server.1=192.168.1.1:2888:3888 server.2=0.0.0.0:2888:3888 来源: CSDN 作者: 中单大魔王 链接: https://blog.csdn.net/qq_33142257/article/details/79836645

Zookeeper日志配置问题

给你一囗甜甜゛ 提交于 2019-12-05 05:12:49
前端时间配置zookeeper日志时出现问题,尽管修改了conf目录下的log4j.properties, 重启zookeeper后仍不起作用。查了下资料,才知道要修改bin目录下的zkEnv.sh。 注:我用的zookeper版本是3.4.5。 总结步骤如下: 1> 修改conf/log4j.properties: # Define some default values that can be overridden by system properties zookeeper.root.logger=INFO,ROLLINGFILE ========= 2> 修改bin/zkEvn.sh文件, if [ "x ${ZOO_LOG4J_PROP} " = "x" ] then ZOO_LOG4J_PROP= "INFO,CONSOLE" fi 改成 if [ "x ${ZOO_LOG4J_PROP} " = "x" ] then ZOO_LOG4J_PROP= "INFO,ROLLINGFILE" fi 3> 还是修改bin/zkEnv.sh 这次是为了指定zookeeper.log的目录, 改下ZOO_LOG_DIR就行了,默认指向当前目录。 启动zkSever.sh start,指定目录下zookeeper.log成功出现。 来源: CSDN 作者: jsky_studio

Zookeeper开发常见问题

﹥>﹥吖頭↗ 提交于 2019-12-05 05:11:46
背景与目的 Zookeeper开发过程中遇到一些常见问题,为了后续开发不犯同样的错误,总结一下此类问题,并进行分析和解决。 适合人员 主要适合zookeeper开发、测试及运维相关人员。 问题与解决 一、 关于zookeeper_init函数的使用 问题描述: 开发人员在调用zookeeper_init函数时,若返回一个非空句柄zhandle_t *zh,则认为初始化成功,这样可能会导致后续操作失败。 问题分析: zhandle_t *zookeeper_init(const char *host, watcher_fn fn, int recv_timeout,const clientid_t *clientid, void *context, int flags) 函 数 返回一个zookeeper客户端与服务器通信的句柄,通常我们仅仅根据返回句柄情况来判断zookeeper 客户端与zookeeper服务器是否 建立连接。如果句柄为空则认为是失败,非空则成功。其实不然,zookeeper_init创建与ZooKeeper服务端通信的句柄以及对应于此句柄的会话,而会话的创建是一个异步的过程,仅当会话建立成功,zookeeper_init才返回一个可用句柄。 问题解决: 如何正确判断zookeepr_init初始化成功,可通过以下三种方式 1、判断句柄的state是否为ZOO