zoo

Modifying Plot in ggplot2 using as.yearmon from zoo

橙三吉。 提交于 2019-12-18 05:10:31
问题 I have created a graph in ggplot2 using zoo to create month bins. However, I want to be able to modify the graph so it looks like a standard ggplot graph. This means that the bins that aren't used are dropped and the bins that are populate the entire bin space. Here is my code: library(data.table) library(ggplot2) library(scales) library(zoo) testset <- data.table(Date=as.Date(c("2013-07-02","2013-08-03","2013-09-04","2013-10-05","2013-11-06","2013-07-03","2013-08-04","2013-09-05","2013-10-06

zookeeper 介绍

我只是一个虾纸丫 提交于 2019-12-18 03:52:02
ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等。 Zookeeper是hadoop的一个子项目,其发展历程无需赘述。在分布式应用中,由于工程师不能很好地使用锁机制,以及基于消息的协调机制不适合在 某些应用中使用,因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文简单分析 zookeeper的工作原理,对于如何使用zookeeper不是本文讨论的重点。 1 Zookeeper的基本概念 1.1 角色 Zookeeper中的角色主要有以下三类,如下表所示: 系统模型如图所示: 1.2 设计目的 1.最终一致性:client不论连接到哪个Server,展示给它都是同一个视图,这是zookeeper最重要的性能。 2 .可靠性:具有简单、健壮、良好的性能,如果消息m被到一台服务器接受,那么它将被所有的服务器接受。 3 .实时性:Zookeeper保证客户端将在一个时间间隔范围内获得服务器的更新信息,或者服务器失效的信息。但由于网络延时等原因,Zookeeper不能保证两个客户端能同时得到刚更新的数据,如果需要最新数据,应该在读数据之前调用sync()接口。 4 .等待无关(wait-free)

R remove groups with only NAs

断了今生、忘了曾经 提交于 2019-12-17 21:17:42
问题 I have a dataframe similar to the one generated by the following structure: library(dplyr) df1 <- expand.grid(region = c("USA", "EUR", "World"), time = c(2000, 2005, 2010, 2015, 2020), scenario = c("policy1", "policy2"), variable = c("foo", "bar")) df2 <- expand.grid(region = c("USA", "EUR", "World"), time = seq(2000, 2020, 1), scenario = c("policy1", "policy2"), variable = c("foo", "bar")) df2 <- filter(df2, !(time %in% c(2000, 2005, 2010, 2015, 2020))) df1$value <- rnorm(dim(df1)[1], 1.5, 1

R: Interpolation of NAs by group

北城以北 提交于 2019-12-17 19:53:12
问题 I would like to perform a linear interpolation in a variable of a data frame which takes into account the: 1) time difference between the two points, 2) the moment when the data was taken and 3) the individual taken for measure the variable. For example in the next dataframe: df <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1,1,1,1,1,2,2,2), Value=c(1, 2, 3, NA, 5, NA, 7, 5, NA, 7)) df I would like to obtain: result <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1

Interpolate zoo object with missing Dates

笑着哭i 提交于 2019-12-17 16:07:57
问题 I have a climate time series with missing Dates (not missing values). For example: n = 15 full.dates = seq(Sys.Date(), by = 'day', length = n) serie.dates = full.dates[c(1:10, 12, 15)] # missing 11, 13, 14 y = rnorm(n) require(zoo) serie = zoo(y, serie.dates) How can i 'fill' (using interpolation) these missing points, given the 'full.dates' vector? Thanks! 回答1: Merge with an "empty" object that has all the dates you want, then use na.approx (or na.spline , etc.) to fill in the missing values

R convert between zoo object and data frame, results inconsistent for different numbers of columns?

喜欢而已 提交于 2019-12-17 15:38:36
问题 I have difficulty switching between data frames and zoo objects, particularly keeping meaningful column names, and inconsistencies between univariate and multivariate cases: library(zoo) #sample data, two species counts over time t = as.Date(c("2012-01-01", "2012-01-02", "2012-01-03", "2012-01-04")) n1 = c(4, 5, 9, 7) #counts of Lepisma saccharina n2 = c(2, 6, 0, 11) #counts of Thermobia domestica df = data.frame(t, n1, n2) colnames(df) <- c("Date", "Lepisma saccharina", "Thermobia domestica"

Aggregate by week in R

孤人 提交于 2019-12-17 10:49:17
问题 In R I frequently aggregate daily data (in a zoo ) by month, using something like this: result <- aggregate(x, as.yearmon, "mean", na.rm=TRUE) Is there a way that I can do this by week? 回答1: The easiest thing to do is to use the apply.weekly function from xts . > apply.weekly(zoo(1:10, as.Date("2010-01-01") + 1:10), mean) 2010-01-03 2010-01-10 2010-01-11 3 42 10 来源: https://stackoverflow.com/questions/4309248/aggregate-by-week-in-r

merging a large list of xts objects

坚强是说给别人听的谎言 提交于 2019-12-17 09:50:17
问题 I have a list of xts objects that are mutually exclusive days. I would like to merge the list into one large xts object. My attempt at doing this was to" merged_reg_1_min_prices <- do.call(cbind, reg_1_min_prices) However this seems to run out of memory. reg_1_min_prices is 6,000 days of 1 minute returns on mutually exclusive days so it's not very large. Does anyone know how to get around this? To be clear: reg_1_min_prices contains mutually exclusive days with 1 minute prices on each day and

Fill NA in a time series only to a limited number

不打扰是莪最后的温柔 提交于 2019-12-17 09:48:11
问题 Is there a way we can fill NA s in a zoo or xts object with limited number of NA s forward. In other words like fill NA s up to 3 consecutive NA s, and then keep the NA s from the 4th value on until a valid number. Something like this. library(zoo) x <- zoo(1:20, Sys.Date() + 1:20) x[c(2:4, 6:10, 13:18)] <- NA x 2014-09-20 2014-09-21 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 1 NA NA NA 5 NA NA 2014-09-27 2014-09-28 2014-09-29 2014-09-30 2014-10-01 2014-10-02 2014-10-03 NA NA NA

R: merge two irregular time series

对着背影说爱祢 提交于 2019-12-17 08:53:42
问题 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