zoo

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

放肆的年华 提交于 2019-12-07 12:41:44
问题 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

Clueless about this error: wrong sign in 'by' argument

江枫思渺然 提交于 2019-12-06 19:54:29
I have the following dataset: >k1[1:10,] id web_name first_name second_name position date team1 team2 game_week points home_away team_scored team_conceded minutes goals assists 1 1 Fabianski Lukasz Fabianski Goalkeeper 17/08/13 ARS AVL 1 0 H 1 3 0 0 0 2 1 Fabianski Lukasz Fabianski Goalkeeper 24/08/13 ARS FUL 2 0 A 3 1 0 0 0 3 1 Fabianski Lukasz Fabianski Goalkeeper 01/09/13 ARS TOT 3 0 H 1 0 0 0 0 4 1 Fabianski Lukasz Fabianski Goalkeeper 14/09/13 ARS SUN 4 0 A 3 1 0 0 0 5 1 Fabianski Lukasz Fabianski Goalkeeper 22/09/13 ARS STK 5 0 H 3 1 0 0 0 6 1 Fabianski Lukasz Fabianski Goalkeeper 28/09

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

。_饼干妹妹 提交于 2019-12-06 19:25:29
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 : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ... $ vial : Factor w/ 4 levels "1","2",

Using R to create and merge zoo object time series from csv files

荒凉一梦 提交于 2019-12-06 16:07:29
I have a large set of csv files in a single directory. These files contain two columns, Date and Price . The filename of filename.csv contains the unique identifier of the data series. I understand that missing values for merged data series can be handled when these times series data are zoo objects. I also understand that, in using the na.locf(merge() function , I can fill in the missing values with the most recent observations. I want to automate the process of. loading the *.csv file columnar Date and Price data into R dataframes. establishing each distinct time series within the Merged zoo

rolling regression with confidence interval (tidyverse)

半城伤御伤魂 提交于 2019-12-06 14:57:46
问题 This is related to rolling regression by group in the tidyverse? Consider again this simple example library(dplyr) library(purrr) library(broom) library(zoo) library(lubridate) mydata = data_frame('group' = c('a','a', 'a','a','b', 'b', 'b', 'b'), 'y' = c(1,2,3,4,2,3,4,5), 'x' = c(2,4,6,8,6,9,12,15), 'date' = c(ymd('2016-06-01', '2016-06-02', '2016-06-03', '2016-06-04', '2016-06-03', '2016-06-04', '2016-06-05','2016-06-06'))) group y x date <chr> <dbl> <dbl> <date> 1 a 1.00 2.00 2016-06-01 2 a

merge two time series with different time granularities

冷暖自知 提交于 2019-12-06 12:26:05
I have two CsV files containing time series data. I want to merge the two into a single file. File1 has periodic data at 1-minute intervals. File2 has event-triggered data that is not periodic. The timestamps for data in File2 may or may not coincide with data in File1. I want to merge the two datasets to create a dataset whose timestamps are a union of Data1 and Data2. For timestamps that are not common to both, I want the missing entries for the corresponding dataset to be indicated as NA. Here is a sample input for File1: Time A1 A2 2013-08-05 00:00:00 2 1 2013-08-05 00:01:00 2 1 2013-08-05

Seasonal aggregate of monthly data

痞子三分冷 提交于 2019-12-06 11:50:47
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 Jan.2009 Feb.2009 ... Dec.2010 1 1 1 -0.6264538 1.5952808 ... 2.1726117 2 2 2 0.1836433 0.3295078 ...

Zookeeper C API 指南二(监视(Wathes), 基本常量和结构体介绍)

做~自己de王妃 提交于 2019-12-06 08:54:43
接上一篇《 Zookeeper C API 指南一(准备工作) 》,本问将重点介绍 Zookeeper 监视(Watches),以及 Zookeeper C API 中基本的常量与结构体。 Zookeeper 监视(Watches) 简介 Zookeeper C API 的声明和描述在 include/zookeeper.h 中可以找到,另外大部分的 Zookeeper C API 常量、结构体声明也在 zookeeper.h 中,如果如果你在使用 C API 是遇到不明白的地方,最好看看 zookeeper.h,或者自己使用 doxygen 生成 Zookeeper C API 的帮助文档。 Zookeeper 中最有特色且最不容易理解的是监视(Watches)。Zookeeper 所有的读操作—— getData() , getChildren() , 和 exists() 都 可以设置监视(watch),监视事件可以理解为一次性的触发器, 官方定义如下: a watch event is one-time trigger, sent to the client that set the watch, which occurs when the data for which the watch was set changes。对此需要作出如下理解: (一次性触发)One

irregular time series data- can I make it regular? in r

放肆的年华 提交于 2019-12-06 06:07:41
I have data that was programmed to acquire information every 5 hours which means multiple data points per day. The problem is sometimes the data logger fails or batteries die or whatever and there are missing data or failed attempts. All of my analysis I do is based upon these dates. I need to sort and filter and select everything based on this date/time stamp. As of right now I am going through "long winded" scripts just to select and subset my data. Additionally I have several data loggers (individuals) so I am also batch processing. For instance, I want to subset and use only one data point

Adding column to zoo object

断了今生、忘了曾经 提交于 2019-12-06 05:39:11
I have a zoo object z with 10 rows and 2 columns as follow: Date Return 1986-01 0.00308215260513781 1986-02 0.00305355599484584 . . . . . . 1986-10 0.00349830477430457 I need a new zoo object that contains the z object along with a new column X from data frame df . The desired output should look like: Date Return X 1986-01 0.00308215260513781 11 1986-02 0.00305355599484584 12 . . . . . . . . . 1986-10 0.00349830477430457 20 I used the following code: new= merge(z , df$X) However, it gives the results not as desired but with each value in X assigned to each row of z . The new object now has 100