zoo

Basic lag in R vector/dataframe

有些话、适合烂在心里 提交于 2019-11-26 15:09:01
Will most likely expose that I am new to R, but in SPSS, running lags is very easy. Obviously this is user error, but what I am missing? x <- sample(c(1:9), 10, replace = T) y <- lag(x, 1) ds <- cbind(x, y) ds Results in: x y [1,] 4 4 [2,] 6 6 [3,] 3 3 [4,] 4 4 [5,] 3 3 [6,] 5 5 [7,] 8 8 [8,] 9 9 [9,] 3 3 [10,] 7 7 I figured I would see: x y [1,] 4 [2,] 6 4 [3,] 3 6 [4,] 4 3 [5,] 3 4 [6,] 5 3 [7,] 8 5 [8,] 9 8 [9,] 3 9 [10,] 7 3 Any guidance will be much appreciated. Another way to deal with this is using the zoo package, which has a lag method that will pad the result with NA: require(zoo) >

Replace NA with previous or next value, by group, using dplyr

拥有回忆 提交于 2019-11-26 14:39:27
I have a data frame which is arranged by descending order of date. ps1 = data.frame(userID = c(21,21,21,22,22,22,23,23,23), color = c(NA,'blue','red','blue',NA,NA,'red',NA,'gold'), age = c('3yrs','2yrs',NA,NA,'3yrs',NA,NA,'4yrs',NA), gender = c('F',NA,'M',NA,NA,'F','F',NA,'F') ) I wish to impute(replace) NA values with previous values and grouped by userID In case the first row of a userID has NA then replace with the next set of values for that userid group. I am trying to use dplyr and zoo packages something like this...but its not working cleanedFUG <- filteredUserGroup %>% group_by(UserID)

Is there a _fast_ way to run a rolling regression inside data.table?

久未见 提交于 2019-11-26 12:46:06
问题 I am running rolling regressions in R, using with the data stored in a data.table . I have a working version, however it feels like a hack -- I am really using what i know from the zoo package, and none of the magic in data.table ... thus, it feels slower than it ought to be. Incorporating Joshua\'s suggestion - below - there is a speedup of ~12x by using lm.fit rather than lm . (revised) Example code: require(zoo) require(data.table) require(rbenchmark) set.seed(1) tt <- seq(as.Date(\"2011

Moving average of previous three values in R

血红的双手。 提交于 2019-11-26 07:44:26
问题 In the zoo package there is a function called rollmean, which enables you to make moving averages. The rollmean(x,3) will take the previous, current and next value (ie 4, 6 and 2) in the table below. This is shown in the second column. x rollmean ma3 4 6 4.0 2 4.3 5 3.0 4.0 2 6.3 4.3 12 6.0 3.0 4 6.0 6.3 2 6.0 I would like to get the same job done, but by averaging out the previous 3 values in the fourth row. This is displayed in the third column. Can anybody tell me the name of the function

Adaptive moving average - top performance in R

拥有回忆 提交于 2019-11-26 05:24:48
问题 I am looking for some performance gains in terms of rolling/sliding window functions in R. It is quite common task which can be used in any ordered observations data set. I would like to share some of my findings, maybe somebody would be able to provide feedback to make it even faster. Important note is that I focus on the case align=\"right\" and adaptive rolling window, so width is a vector (same length as our observation vector). In case if we have width as scalar there are already very

Basic lag in R vector/dataframe

為{幸葍}努か 提交于 2019-11-26 04:11:57
问题 Will most likely expose that I am new to R, but in SPSS, running lags is very easy. Obviously this is user error, but what I am missing? x <- sample(c(1:9), 10, replace = T) y <- lag(x, 1) ds <- cbind(x, y) ds Results in: x y [1,] 4 4 [2,] 6 6 [3,] 3 3 [4,] 4 4 [5,] 3 3 [6,] 5 5 [7,] 8 8 [8,] 9 9 [9,] 3 3 [10,] 7 7 I figured I would see: x y [1,] 4 [2,] 6 4 [3,] 3 6 [4,] 4 3 [5,] 3 4 [6,] 5 3 [7,] 8 5 [8,] 9 8 [9,] 3 9 [10,] 7 3 Any guidance will be much appreciated. 回答1: Another way to deal

Replace NA with previous or next value, by group, using dplyr

巧了我就是萌 提交于 2019-11-26 02:38:11
问题 I have a data frame which is arranged by descending order of date. ps1 = data.frame(userID = c(21,21,21,22,22,22,23,23,23), color = c(NA,\'blue\',\'red\',\'blue\',NA,NA,\'red\',NA,\'gold\'), age = c(\'3yrs\',\'2yrs\',NA,NA,\'3yrs\',NA,NA,\'4yrs\',NA), gender = c(\'F\',NA,\'M\',NA,NA,\'F\',\'F\',NA,\'F\') ) I wish to impute(replace) NA values with previous values and grouped by userID In case the first row of a userID has NA then replace with the next set of values for that userid group. I am

Yum安装mesos+zookeeper+marathon管理docker集群

烂漫一生 提交于 2019-11-25 23:27:30
Yum安装mesos+zookeeper+marathon管理docker集群 Apache-Mesos简介 Apache-Mesos是一款基于多资源(内存、CPU、磁盘、端口等)调度的开源集群管理套件,能使容错和分布式系统更加容易使用。官方网站http://mesos.apache.org/ ,软件能够自由下载使用。 Apache-Mesos工作原理 Apache-Mesos采用Master/Slave结构来简化设计,将Master做得尽可能轻量级,仅保存各种计算框架(Framework)和Mesos Slave的状态信息,这些状态很容易在Mesos出现故障的时候被重构,除此之外Mesos还使用Zookeeper解决Master单点故障的问题。 Apache-Mesos基本术语 Mesos Master:负责管理各个Framework和Slave,并将Slave上的资源分配给各个Framework。 Mesos Slave:负责管理本节点上的各个Mesos Task,为各个Executor分配资源。 Framework:计算机框架,如:Hadoop、Spark等,可以通过MesosSchedulerDiver接入Mesos。 Executor:执行器,在Mesos Slave上安装,用于启动计算框架中的Task。 Zookeeper简介

一起走进动物园管理员——ZooKeeper

假如想象 提交于 2019-11-25 22:27:58
一、ZooKeeper简介 1. ZooKeeper是什么 ​ Apache ZooKeeper是一个开源的分布式服务框架,为分布式应用提供协调服务,用来解决分布式应用中的数据管理问题,如:配置管理、域名服务、分布式同步、集群管理等 官网 https://zookeeper.apache.org/ ZooKeeper视频教程 http://edu.51cto.com/course/16190.html 2. ZooKeeper组成 ​ 主要包括两部分:文件系统、通知机制 2.1 文件系统 ​ ZooKeeper维护一个类似Linux文件系统的数据结构,用于存储数据 数据模型结构是一种树形结构,由许多节点构成 每个节点叫做ZNode(ZooKeeper Node) 每个节点对应一个唯一路径,通过该路径来标识节点,如 /app1/p_2 每个节点只能存储大约1M的数据 ​ 节点类型有四种: 持久化目录节点 persistent 客户端与服务器断开连接,该节点仍然存在 持久化顺序编号目录节点 persistent_sequential 客户端与服务器断开连接,该节点仍然存在,此时节点会被顺序编号,如:000001、000002..... 临时目录节点 ephemeral 客户端与服务器断开连接,该节点会被删除 临时顺序编号目录节点 ephemeral_sequential

Converting year and month (“yyyy-mm” format) to a date?

倾然丶 夕夏残阳落幕 提交于 2019-11-25 22:16:37
问题 I have a dataset that looks like this: Month count 2009-01 12 2009-02 310 2009-03 2379 2009-04 234 2009-05 14 2009-08 1 2009-09 34 2009-10 2386 I want to plot the data (months as x values and counts as y values). Since there are gaps in the data, I want to convert the Information for the Month into a date. I tried: as.Date(\"2009-03\", \"%Y-%m\") But it did not work. Whats wrong? It seems that as.Date() requires also a day and is not able to set a standard value for the day? Which function