zoo

R: rollapplyr and lm factor error: Does rollapplyr change variable class?

狂风中的少年 提交于 2019-12-08 03:40:07
问题 This question builds upon a previous one which was nicely answered for me here. R: Grouped rolling window linear regression with rollapply and ddply Wouldn't you know that the code doesn't quite work when extended to the real data rather than the example data? I have a somewhat large dataset with the following characteristics. str(T0_satData_reduced) 'data.frame': 45537 obs. of 5 variables: $ date : POSIXct, format: "2014-11-17 08:47:35" "2014-11-17 08:47:36" "2014-11-17 08:47:37" ... $ trial

multipart index in zoo timeseries

感情迁移 提交于 2019-12-08 01:33:05
问题 I am working with trade dataset with thousands of rows. Every record has a unique key based on a symbol and date. Trade records for a given symbol are irregular, hence using zoo will be natural choice. I need to use lag and merge to create a new dataset. However, I don't know how to setup multi-column index in zoo in order to use lag function. Below is a sample dataset and intended output. df = data.frame( dt = as.Date(c("2015-01-01", "2015-01-05", "2015-01-06", "2015-01-01", "2015-01-02")),

Seasonal aggregate of monthly data

不问归期 提交于 2019-12-08 00:25:55
问题 I have dataframe df with x,y,and monthly.year data for each x,y point. I am trying to get the seasonal aggregate. I need to calculate seasonal means i.e. For winter mean of (December,January,February); for Spring mean of (March,April,May), for Summer mean of (June,July,August) and for autumn mean of (September,October,November). The data looks similar to: set.seed(1) df <- data.frame(x=1:3,y=1:3, matrix(rnorm(72),nrow=3) ) names(df)[3:26] <- paste(month.abb,rep(2009:2010,each=12),sep=".") x y

dplyr mutate in zoo object

自闭症网瘾萝莉.ら 提交于 2019-12-07 17:20:17
问题 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. 回答1: 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

How can I create dates in Year/Semester format in R?

╄→гoц情女王★ 提交于 2019-12-07 17:12:10
问题 I want to aggregate zoo data in R by two, four or six months periods. There are only two avaliable options for this type of date processing, using: a) as.yearmon => process daily data grouped by each month b) as.yearqtr => process daily data grouped by fixed groups of 3 months periods (jan-mar, apr-jun, jul-set and oct-dec). A minimal example library(zoo) # creating a vector of Dates dt = as.Date(c("2001-01-01","2001-01-02","2001-04-01","2001-05-01","2001-07-01","2001-10-01"), "%Y-%m-%d") #

matching time vectors of different length: a tricky one

心已入冬 提交于 2019-12-07 15:37:45
问题 I have two sets of measurements from different machines. They are measured over time, at slightly different intervals - e.g. one makes a measurement every 5 mins, but the other, every 3 mins. The advantage is that the one every 5 mins is computed as an average over the whole interval so the values should correspond roughly to one another. I would like to expand the vector with measurements every 5 minutes (Light) so that its values are roughly synchronous with the values in vector of

zk系列-c++下zookeeper使用实例

女生的网名这么多〃 提交于 2019-12-07 14:38:44
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务。分布式应用可以使用它来实现诸如:统一命名服务、配置管理、分布式锁服务、集群管理等功能。公司常用到的是Java服务集群的管理。 1.函数介绍 [cpp] view plain copy //create a handle to used communicate with zookeeper zhandle_t *zookeeper_init( const char *host, watcher_fn fn, int recv_timeout, const clientid_t *clientid, void *context, int flags) //create a node synchronously int zoo_create(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, char *path_buffer, int path_buffer_len); //lists the children of a node synchronously. int zoo_wget_children(zhandle_t *zh, const char

R replacing missing values with the mean of surroundings values

折月煮酒 提交于 2019-12-07 14:32:21
问题 My dataset looks like the following (let's call it "a"): date value 2013-01-01 12.2 2013-01-02 NA 2013-01-03 NA 2013-01-04 16.8 2013-01-05 10.1 2013-01-06 NA 2013-01-07 12.0 I would like to replace the NA by the mean of the closest surroundings values (the previous and the next values in the series). I tried the following but I am not convinced by the output... miss.val=which(is.na(a$value)) library(zoo) z=zoo(a$value,a$date) z.corr=na.approx(z) z.corr[(miss.val-1):(miss.val+1),] 回答1: Using

tracking a cohort over time in R

蹲街弑〆低调 提交于 2019-12-07 13:00:29
问题 I have a sample dataset of user ids and months in which a transaction was made. My goal is to calculate, month over month, how many of the original users made transactions. In other words, how many users that were new in January also made transactions in February, March, and April. How many users that were new in February made transactions in March and April, and so on. > data date user_id 1 Jan 2017 1 2 Jan 2017 2 3 Jan 2017 3 4 Jan 2017 4 5 Jan 2017 5 6 Feb 2017 1 7 Feb 2017 3 8 Feb 2017 5

Lags in R within specific subsets?

六眼飞鱼酱① 提交于 2019-12-07 12:59:30
Suppose I have the following dataframe: df <- data.frame("yearmonth"=c("2005-01","2005-02","2005-03","2005-01","2005-02","2005-03"),"state"=c(1,1,1,2,2,2),"county"=c(3,3,3,3,3,3),"unemp"=c(4.0,3.6,1.4,3.7,6.5,5.4)) I'm trying to create a lag for unemployment within each unique state-county combination. I want to end up with this: df2 <- data.frame("yearmonth"=c("2005-01","2005-02","2005-03","2005-01","2005-02","2005-03"),"state"=c(1,1,1,2,2,2),"county"=c(3,3,3,3,3,3),"unemp"=c(4.0,3.6,1.4,3.7,6.5,5.4),"unemp_lag"=c(NA,4.0,3.6,NA,3.7,6.5)) Now, imagine this situation except with thousands of