zoo

Why is zoo::rollmean slow compared to a simple Rcpp implementation?

ⅰ亾dé卋堺 提交于 2019-12-04 08:47:03
问题 zoo::rollmean is a helpful function that returns the rolling mean of a time series; for vector x of length n and window size k it returns the vector c(mean(x[1:k]), mean(x[2:(k+1)]), ..., mean(x[(n-k+1):n])) . I noticed that it seemed to be running slowly for some code I was developing, so I wrote my own version using the Rcpp package and a simple for loop: library(Rcpp) cppFunction("NumericVector rmRcpp(NumericVector dat, const int window) { const int n = dat.size(); NumericVector ret(n

plotting multiple xts objects in one window

僤鯓⒐⒋嵵緔 提交于 2019-12-04 08:02:38
I have found some answers to this online but for some reason am interpreting incorrectly because I cannot get it to work. My goal is to simply use the xts plotting feature (with the the way it creates the axis, gridlines,etc.) to plot multiple plots: x <- xts(data.frame(a=1:100, b=100:1),seq(from=as.Date("2010-01-01"), by="days", len=100)) > plot(x, screens=1) Warning messages: 1: In plot.xts(x, screens = 1) : only the univariate series will be plotted 2: In plot.window(...) : "screens" is not a graphical parameter 3: In plot.xy(xy, type, ...) : "screens" is not a graphical parameter 4: In

Wrong result from mean(x, na.rm = TRUE)

霸气de小男生 提交于 2019-12-04 04:44:17
问题 I want to compute the mean, min and max of a series of Managers returns, as follows: ManagerRet <-data.frame(diff(Managerprices)/lag(Managerprices,k=-1)) I then replace return = 0 with NaN since data are extracted from a database and not all the dates are populated. ManagerRet = replace(ManagerRet,ManagerRet==0,NaN) I have the following 3 function > min(ManagerRet,na.rm = TRUE) [1] -0.0091716 > max(ManagerRet,na.rm = TRUE) [1] 0.007565 > mean(ManagerRet,na.rm = TRUE)*252 [1] NaN Why the mean

Linux 之redis 的安装及使用

馋奶兔 提交于 2019-12-04 01:11:26
一、redis的优缺点   redis的优点:        属于内存型的数据库,存储速度非常快   redis的缺点:        断电数据会丢失        redis服务挂掉之后数据也会丢失 二、 redis的安装   1、 下载redis源码包: wget http://download.redis.io/releases/redis-5.0.2.tar.gz     2、解压缩 tar -zxvf redis-5.0.2.tar.gz -C 指定解压目录    3、 编译源文件 cd redis-5.0.2 make && make install    4、创建redis配置文件 mkdir -p /opt/redis_conf cd /opt/redis_conf vim redis-6379.conf port 6379 # 运行在6379的redis数据库实例 daemonize yes # 后台运行redis pidfile /data/6379/redis.pid # 存放redis pid的文件 loglevel notice # 日志等级 logfile "/data/6379/redis.log" # 指定redis日志文件的生成目录 dir /data/6379 # 指定redis数据文件夹的目录 protected-mode yes # 安全模式

阿里云服务器centos单机搭建zookeeper集群报错

三世轮回 提交于 2019-12-03 23:30:38
目录 1.错误1 1.1查看集群状态 1.2.查看日志 1.3分析 1.3.1端口没开 1.3.2检查配置文件 2.错误2 2.1查看集群状态 2.2查看日志 2.3解决 1.错误1 1.1查看集群状态 今天在阿里云服务器centos单机搭建zookeeper集群 查看集群状态的时候,总是提示: Error contacting service. It is probably not running. 可是明明已经提示启动成功了啊???? 1.2.查看日志 查看zookeeper01/bin/zookeeper.log,出现以下错误: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl

linux-zookeeper安装、配置

浪子不回头ぞ 提交于 2019-12-03 18:19:45
1、下载zookeeper包 (地址: https://www-eu.apache.org/dist/zookeeper/ ) 2、上传zookeeper包到指定位置(例如: /usr/local/software/zookeeper) -------------------------------------单节点配置--------------------------------------------------- 3、解压:tar -xvf zookeeper3-4.tar.gz 4、进入zookeeper3-4/conf后,cp zoo_sample.cfg zoo.cfg 5、vim zoo.cfg (设置dataDir和dataLogDir位置,路径位置就创建在zookeeper3-4目录下即可) 6、vim /etc/profile ( 设置 zookeeper的环境变量: export ZOO_HOME=/usr/local/software/zookeeper/zookeeper1 export PATH=$PATH:$ZOO_HOME/bin:$ZOO_HOME/conf ) 7、source /etc/profile 使修改的配置生效 8、启动:zkServer.sh start 9、查看:zkServer.sh status 注:前提必须安装了jdk,

Reading csv with date and time

☆樱花仙子☆ 提交于 2019-12-03 16:01:03
问题 I am working in R and reading csv which has date and time in its first column. I want to import this csv file in R first and then convert it to zoo obect. I am using the code in R EURUSD <- as.xts(read.zoo("myfile.csv",sep=",",tz="",header=T)) My csv file contain data in the format: Date,Open,Low,High,Close 2006-01-02 10:01:00,2822.9,2825.45,2822.1,2824.9 2006-01-02 10:02:00,2825,2825.9,2824,2824.95 2006-01-02 10:03:00,2824.55,2826.45,2824,2826.45 2006-01-02 10:04:00,2826.45,2826.45,2824.9

regressions with xts in R

爷,独闯天下 提交于 2019-12-03 15:04:33
问题 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. 回答1:

Convert data.frame to xts object and preserve types

天大地大妈咪最大 提交于 2019-12-03 10:09:23
问题 Is there a way to create an xts object from a data.frame and preserve data type? My numerics are being converted to character. This post from 2009 suggests merging columns into an existing xts: http://r.789695.n4.nabble.com/as-xts-convert-all-my-numeric-data-to-character-td975564.html It wasn't clear whether that is the ONLY way to do this. Seems a bit of a hack and cumbersome for large data frames. I would think out-of-the-box xts would respect the datatypes. 回答1: No, you can't. xts/zoo

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