zoo

Forcing end of quarter date for as.Date(as.yearqtr())

ⅰ亾dé卋堺 提交于 2020-08-07 09:53:31
问题 as.yearqtr() from the zoo package appears to use the beginning of the quarter: library(zoo) x <- "2015-05-17" x <- as.Date(x) x <- as.Date(as.yearqtr(x)) x # [1] "2015-04-01" How might I instead grab the end of quarter? x # [1] "2015-06-30" Thanks! 回答1: Use frac = 1 as shown: x <- as.Date("2015-05-17") as.Date( as.yearqtr(x), frac = 1 ) giving: [1] "2015-06-30" 回答2: library(zoo) x <- as.Date("2015-05-17") x <- as.Date(as.yearqtr(x)+0.25)-1 x # [1] "2015-06-30" as.yearqtr(x)+0.25 gives you the

Rollapply over data.table rows with subset calculations in function

跟風遠走 提交于 2020-07-09 13:09:42
问题 I want to rollapply a function on a data.table. And in the function I would like to work with the data.table subset, so that the example below works. library(zoo) library(data.table) dt <- data.table(i = 1:100, x = sample(1:10, 100, replace = T), y = sample(1:10, 100, replace = T)) rollapply(dt, width=10, FUN = function(dt_slice) dt_slice[, mean(x == y)]) 回答1: You can use rollapply , or sapply / outer , to get a matrix of indices and then apply over that matrix with the operation you want

Rollapply over data.table rows with subset calculations in function

℡╲_俬逩灬. 提交于 2020-07-09 13:09:35
问题 I want to rollapply a function on a data.table. And in the function I would like to work with the data.table subset, so that the example below works. library(zoo) library(data.table) dt <- data.table(i = 1:100, x = sample(1:10, 100, replace = T), y = sample(1:10, 100, replace = T)) rollapply(dt, width=10, FUN = function(dt_slice) dt_slice[, mean(x == y)]) 回答1: You can use rollapply , or sapply / outer , to get a matrix of indices and then apply over that matrix with the operation you want

Rollapply over data.table rows with subset calculations in function

社会主义新天地 提交于 2020-07-09 13:08:11
问题 I want to rollapply a function on a data.table. And in the function I would like to work with the data.table subset, so that the example below works. library(zoo) library(data.table) dt <- data.table(i = 1:100, x = sample(1:10, 100, replace = T), y = sample(1:10, 100, replace = T)) rollapply(dt, width=10, FUN = function(dt_slice) dt_slice[, mean(x == y)]) 回答1: You can use rollapply , or sapply / outer , to get a matrix of indices and then apply over that matrix with the operation you want

Convert numeric date format (YYYYMMDD; 20150101) into Year-Month

若如初见. 提交于 2020-07-03 07:27:56
问题 Can anyone of you help in converting the date from 20150101 to abbreviated form Jan-2015 ? I tried the below method. x = 20150101 zoo::as.yearmon(x, "%b-%y") But I got the below error Error in charToDate(x) : character string is not in a standard unambiguous format Any help would be very much appreciated. 回答1: There are two problems with the code in the question: the input format is specified as "%b-%y" but should be "%y%m" we wish to use as.yearmon.character here rather than as.yearmon

convert a irregular time series of a data table with factors into a regular time series in R

风格不统一 提交于 2020-06-17 09:07:12
问题 I am trying to convert a irregular time series of a data table into a regular time series. My data looks like this library(data.table) dtRes <- data.table(time = c(0.1, 0.8, 1, 2.3, 2.4, 4.8, 4.9), abst = c(1, 1, 1, 0, 0, 3, 3), farbe = as.factor(c("keine", "keine", "keine", "keine", "keine", "rot", "blau")), gier = c(2.5, 2.5, 2.5, 0, 0, 3, 3), goff = as.factor(c("haus", "maus", "toll", "maus", NA, "maus", "maus")), huft = as.factor(c(NA, NA, NA, "wolle", "wolle", "holz", "holz")), mode = c

is there no option for step size in pandas.DataFrame.rolling? is there another function that will do this for me?

為{幸葍}努か 提交于 2020-05-31 06:25:40
问题 In R you can compute a rolling mean with a specified window that can shift by a specified amount each time. However maybe I just haven't found it anywhere but it doesn't seem like you can do it in pandas or some other python library? Does anyone know of a way around this. I'll give you an example of what I mean: Here we have half-monthly data, and I am computing the two month moving average, that shifts each month. So in R I would do something like: two_month__movavg=rollapply(mydata,4,mean

Rolling Standard Deviation in a Matrix in R

人盡茶涼 提交于 2020-03-17 09:24:39
问题 Bellow is a stock daily returns matrix example ( ret_matriz ) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489 -0.031010237 -0.047439725 -0.040229625 -0.030552275 -0.010409016 [3,] -0.022668170 -0.027012078 -0.022668170 -0.050372843 -0.080732363 0.005218051 [4,] -0.057468428 -0.074922051 -0.068414670 -0.044130126 -0.069032911 -0.057468428 [5,] 0.011897277 -0.004705891 0.035489885 -0.005934736 -0.006024115

Rolling Standard Deviation in a Matrix in R

别说谁变了你拦得住时间么 提交于 2020-03-17 09:24:11
问题 Bellow is a stock daily returns matrix example ( ret_matriz ) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489 -0.031010237 -0.047439725 -0.040229625 -0.030552275 -0.010409016 [3,] -0.022668170 -0.027012078 -0.022668170 -0.050372843 -0.080732363 0.005218051 [4,] -0.057468428 -0.074922051 -0.068414670 -0.044130126 -0.069032911 -0.057468428 [5,] 0.011897277 -0.004705891 0.035489885 -0.005934736 -0.006024115

Zookeeper入门及单机及集群环境搭建

♀尐吖头ヾ 提交于 2020-03-17 07:28:27
1.Zookeeper简介 Zookeeper是一个分布式服务框架,以前是Apache Hadoop 的一个子项目,现在是Apache的一个独立顶级项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。有关分布式的相关问题请查阅上篇博客: 分布式系统问题及解决方案 2.设计目标 ZooKeeper简单。ZooKeeper允许分布式进程通过共享的分层名称空间相互协调,该命名空间的组织方式类似于标准文件系统。名称空间由数据寄存器(在ZooKeeper看来,称为znode)组成,它们类似于文件和目录。与设计用于存储的典型文件系统不同,ZooKeeper数据保留在内存中,这意味着ZooKeeper可以实现高吞吐量和低延迟数。 ZooKeeper特性还包括高性能、高可用性、严格有序。ZooKeeper的性能方面意味着它可以在大型的分布式系统中使用。可靠性方面使它不会成为单点故障。严格有序意味着可以在客户端上实现复杂的同步原语。 ZooKeeper可复制。像它协调的分布式进程一样,ZooKeeper本身也可以在称为集合的一组主机上进行复制。组成ZooKeeper服务的服务器都必须彼此了解。它们维护内存中的状态图像,以及持久存储中的事务日志和快照。只要大多数服务器可用,ZooKeeper服务将可用