zoo

tracking a cohort over time in R

北慕城南 提交于 2019-12-06 03:51:44
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 9 Feb 2017 7 10 Feb 2017 9 11 Mar 2017 2 12 Mar 2017 4 13 Mar 2017 6 14 Mar 2017 8 15 Mar 2017 10 16

plotting multiple xts objects in one window

╄→гoц情女王★ 提交于 2019-12-06 02:51:22
问题 I have found some answers to this online but for some reason am interpreting incorrectly because I cannot get it to work. My goal is to simply use the xts plotting feature (with the the way it creates the axis, gridlines,etc.) to plot multiple plots: x <- xts(data.frame(a=1:100, b=100:1),seq(from=as.Date("2010-01-01"), by="days", len=100)) > plot(x, screens=1) Warning messages: 1: In plot.xts(x, screens = 1) : only the univariate series will be plotted 2: In plot.window(...) : "screens" is

What is the difference the zoo object and ts object in R?

£可爱£侵袭症+ 提交于 2019-12-06 02:06:38
问题 I want to know the differences into use ts() or zoo() function. 回答1: A zoo object has the time values (possibly irregular) in an index attribute displayed like a row name at the console by the print.zoo method and the values in a matrix or atomic vector which places constraints on the values that can be used (generally numeric, but necessarily all of a single mode, i.e. not as a list with multiple modes like a dataframe might hold). With pkg:zoo loaded, to get a list of functions that have

zookeeper的安装使用

纵饮孤独 提交于 2019-12-06 01:57:30
下载 zookeeper http://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/ 上传到 /opt/servers 解压 [root@localhost servers]# tar -zxvf zookeeper-3.4.9.tar.gz 进入 /opt/servers/zookeeper-3.4.9/conf 拷贝一份 [root@localhost conf]# cp zoo_sample.cfg zoo.cfg 建立新文件夹 [root@localhost conf]# mkdir -p /opt/servers/zookeeper-3.4.9/zkdatas/ 配置zoo.cfg 来源: https://www.cnblogs.com/adidasshe/p/11955792.html

How to remove a row from zoo/xts object, given a timestamp

白昼怎懂夜的黑 提交于 2019-12-06 01:44:47
问题 I was happily running with this code: z=lapply(filename_list, function(fname){ read.zoo(file=fname,header=TRUE,sep = ",",tz = "") }) xts( do.call(rbind,z) ) until Dirty Data came along with this at the end of one file: Open High Low Close Volume 2011-09-20 21:00:00 1.370105 1.370105 1.370105 1.370105 1 and this at the start of the next file: Open High Low Close Volume 2011-09-20 21:00:00 1.370105 1.371045 1.369685 1.3702 2230 So rbind.zoo complains about a duplicate. I can't use something

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

余生颓废 提交于 2019-12-06 00:36:01
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") # the original dates dt [1] "2001-01-01" "2001-01-02" "2001-04-01" "2001-05-01" "2001-07-01" "2001-10-01"

Dates appearing as decimals in R plot

半腔热情 提交于 2019-12-05 23:06:55
I’m trying to plot some data with month data along the x-axis. Unfortunately the months are appearing as decimals. Any ideas? library(zoo) # Requires the zoo library. theMonths <- as.yearmon(c( "Mar 2011", "Apr 2011", "May 2011", "Jun 2011", "Jul 2011", "Aug 2011", "Sep 2011", "Oct 2011", "Nov 2011", "Dec 2011", "Jan 2012", "Feb 2012")) x <- c(1:12) plot(theMonths,x,axes=FALSE) axis(1,theMonths) # Why do the dates appear on the axis as decimals? If you look at how the yearmon class objects are structured: dput(theMonths) structure(c(2011.16666666667, 2011.25, 2011.33333333333, 2011.41666666667

R replacing missing values with the mean of surroundings values

旧巷老猫 提交于 2019-12-05 21:33:40
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),] Using na.locf (Last Observation Carried Forward) from package zoo : R> library("zoo") R> x <- c(12.2, NA, NA, 16.8,

Convert Excel numeric to date

最后都变了- 提交于 2019-12-05 20:24:17
I have a vector of numeric excel dates i.e. date <- c(42963,42994,42903,42933,42964) The output am I expecting when using excel_to_numeric_date function from janitor package and as.yearmon function from zoo package as.yearmon(excel_numeric_to_date(date)) [1] "Aug 2016" "Sep 2016" "Jun 2017" "Jul 2017" "Aug 2017" . However, the conversion for the first to elements of the date vector are incorrect. The actual result are: as.yearmon(excel_numeric_to_date(date)) [1] "Aug 2017" "Sep 2017" "Jun 2017" "Jul 2017" "Aug 2017" I have tried using different option( modern and mac pre-2011 ) for the date

matching time vectors of different length: a tricky one

别来无恙 提交于 2019-12-05 20:12:39
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 measurements made every 5 minutes. The gap should then be filled with the preceding value Here is an example of