Questions tagged [zoo]

zoo is an R package that provides an S3 class with methods for totally ordered indexed observations.

Filter by
Sorted by
Tagged with
0 votes
2 answers
33 views

Loop function on timeseries works on small df, but not in large df - Error: C stack usage...too close to the limit

I have a dataframe with dates/times (time series), site (grouping var) and value. I have identified the start times of different 'surges' - defined as changes in values of >=2 in 15 mins. For each ...
James White's user avatar
1 vote
2 answers
47 views

Reverse the rollsum function

The column sum_last_3 contains the sum of the last 3 value of the column x using the function zoo::rollsum. Is there a way to recreate the variable x only using the variable sum_last_3 ? library(dplyr)...
qfazille's user avatar
  • 1,623
2 votes
1 answer
26 views

Create a column that ranges between two rows in an ordered dataframe

So I have some GPS data, where the devices turns on and logs the duration of an event whenever said event occurs. At the end of the event, it then takes one to two GPS fixes of where it occurred, ...
André.B's user avatar
  • 588
0 votes
2 answers
41 views

How to input monthly data for time series plot in R?

I have data stored in .csv file which has two columns: Date mean 201001 234 201002 167 ... ... ... 202005 289 (format is yyyymm) I want to create a time series plot for the same. I am ...
Alexia k Boston's user avatar
0 votes
1 answer
32 views

how to ignore groups with all NAs while imputing data

I have a large panel data with 1000s of rows. I want to use group by (gvkey) and impute values for NAs but some groups have all NAs. I want to ignore those groups. These lines of code give me what I ...
Puneet Sachdeva's user avatar
0 votes
1 answer
41 views

rolling function using previous row values [R]

I have some sites (a,b,c) where the soil has a certain maximum capacity (100,200). For each period of time (every row in my dataset), I have calculated the change in water content (change). set.seed(...
Simone Bianchi's user avatar
0 votes
1 answer
37 views

Convert the quarter date column with the last day of each quarter to the first day of each quarter, or vice versa

Suppose I have the following df1 or df2, how can I use R to convert the last day of each quarter to the first day of each quarter in date column, or vice versa? Thanks. df1: df1 <- structure(list(...
ah bon's user avatar
  • 9,131
0 votes
3 answers
182 views

Rolling mean of time series with missing dates in R

R noob (still) here, working in tidyverse / RStudio. I have a tidy dataset where each row has a date, a grouping characteristic, and a value (actual dataset more complicated but that's the core of it):...
TY Lim's user avatar
  • 457
0 votes
2 answers
53 views

A Function that will spit out the quarters to the year 3000 etc

I need to create some code that will allow my team to have a never ending supply of the yearly quarters. i need a function that will spit out for example q1 2020 or q4 in the year 2500. the code i ...
user avatar
0 votes
1 answer
37 views

Applying user defined function to rolling window with zoo

I am working on a research project, and I wanted to recreate a market efficiency measure I have read about in an article. Since I am working on a large data set I decided to automate the process in R. ...
Stakerauo's user avatar
0 votes
0 answers
21 views

R read.zoo drops column names

For a file ts.csv with contents Date,Foo 2000-01-01,1.45 2000-02-01,1.59 the R code library(zoo) infile = "ts.csv" df = read.zoo(infile, header=TRUE, index=1, read=read.csv) print(df) cat(&...
Fortranner's user avatar
  • 2,485
0 votes
1 answer
42 views

Use zoo to calculate difference by group

I have the following data, how to calculate the difference between height and height[0] grouped by id? E.g. group by id, then the first heightdiff will be 0, then next will be height[1]-height[0], etc....
Vons's user avatar
  • 3,067
0 votes
1 answer
38 views

R script to average values every X days using different starting points

I have a long data set measuring height of trees once a week for 8 months. Also recorded are pot number ('pot'), the date of measuring ('date'), weeks since the start of the experiment ('no.week'), ...
Danielle's user avatar
0 votes
0 answers
21 views

How to make never ending quarters in r studio [duplicate]

I was wondering if you could help me with this task i have on R Studio, it is quite an easy task yet.. i just cant do it. it is to firstly format these yearly quarters correctly and to have the ...
user avatar
0 votes
0 answers
15 views

Convert monthly data to zoo type

I want to convert my monthly data to a zoo type. This is what my imported data looks like for 394 obs of 13 variables. How can I properly do this with the zoo function? Please note I don't have any ...
Josephine Frempong's user avatar
0 votes
2 answers
92 views

How to convert year and quarter column into date using zoo?

I'm trying to convert a data-frame column into date format. I'm using the zoo package, but can't get it to work. The desired output is either yyyy-mm-dd, so 4 dates per year. This is what I've tried ...
Tomas R's user avatar
  • 430
0 votes
0 answers
21 views

How can I display the index of a zoo object in a Shiny data table?

I am developing a Shiny app to calculate statistical parameters of ground surface temperature time series in permafrost areas. Short example data can be found here. Expanding on runExample("...
Marc O'Callaghan's user avatar
0 votes
0 answers
27 views

How to assign valid coredata to zoo object RESET Test

I am doing a SUR regression on several airline stocks and COVID Data. Everything works perfectly fine - however the reset test now shows an error message: The dataset contains: Stock Return, Index ...
Moritz's user avatar
  • 1
2 votes
3 answers
45 views

Pivot Wider causing issues when as.yearmon is used

I have the following code: library(zoo) library(xts) df1<-structure(list(Date = structure(c(13523, 13532, 13539, 13551, 13565, 13567, 13579, 13588, 13600, 13607, ...
alec22's user avatar
  • 806
0 votes
1 answer
29 views

read.zoo is not returning needed date format

My initial data is in %y-%m-%d format... using the code returnsgamma <- read.zoo(returns, header = TRUE, sep = ",", FUN = as.chron) the zoo file is returning values in the order %m/%d/%y ...
shay's user avatar
  • 1
0 votes
1 answer
53 views

Changing class from character to numeric when using zoo

Does anyone know how to change a colum of a zoo object from character to numeric? Needed for use in the "evetstudies" function. I create the variable as so: x <-na.omit(df[,(1:3)]) ...
JCO22's user avatar
  • 1
0 votes
0 answers
32 views

using rollapply function from zoo package in R with na.rm argument

I would like to use the rollapply function from the zoo package in R to calculate a moving IQR, but this fails when missing data (NA's) are reached in my data series. data_series <- c(4,7,4,7,3,6,5,...
user8229029's user avatar
0 votes
1 answer
22 views

Want to save to zoo format (write.csv) and retrieve also keep to same format (zoo) with date indexing from tseries library of R

can i keep the same datatype(zoo) and date index when i write.csv and read.csv for the tseries library of R instant of change the datatype to dataframe, actually i want to save to zoo format and ...
Mary's user avatar
  • 769
0 votes
1 answer
96 views

as.yearmon(dates, format = "%b/%Y") return NAs

I have run this code in RStudio: library(zoo) dates <- c("Sep/2012", "Aug/2012", "Jul/2012") dates1 <- as.yearmon(dates, format="%b/%Y") dates1 But it ...
ah bon's user avatar
  • 9,131
0 votes
1 answer
41 views

forecasting AR models with intercept in R using rollapply

Suppose I have an AR(3) simulated data, with an intercept of 3. set.seed(247) library(astsa) sim1 = 3+arima.sim(list(order=c(3,0,0), ar=c(-0.1,-0.3,-0.5)), n=60) pacf(sim1) I can estimate the ...
Maverick Meerkat's user avatar
0 votes
2 answers
45 views

R - Data Frame Forward and Backward Fill

I have a data frame and am trying to fill the missing values with the previous and next values in the data frame. I used the following code, but it did not fill and returns missing values still. I ...
c200402's user avatar
  • 153
0 votes
1 answer
62 views

Is there a faster alternative to the date extension function using the zoo package?

The code posted at the bottom does a clean job of extending dates expressed both (a) as elapsed number of months per Period_1 in the code and (b) in YYYY-MM format defined as Period_2. Item (b) uses ...
Village.Idyot's user avatar
2 votes
2 answers
38 views

Time series - aggregate by a custom period of time

New to zoo/xts. I'm trying to go from monthly values to quarterly aggregates, defined as the sum of monthly values over a 3-month period ending on the last available month. Reproducible example: ...
Andrea M's user avatar
  • 2,286
0 votes
2 answers
46 views

NA and -Inf in the result of rollapply(which uses max) in R

> library(zoo) Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric > z =c(NA,NA,1,2,3) > rollapply(z,width=2,max,fill=NA,align=&...
user2338823's user avatar
0 votes
1 answer
48 views

Rolling average of values that satisfy multiple conditions in R

This is my first question on Stackoverflow, so please bear with me if I make any mistakes or omit necessary information. I have a dataset consisting of a time series where I need to find the 5-day ...
Hans Peter's user avatar
1 vote
2 answers
55 views

Is it possible to get the specific index of occurence when working with period.apply?

Assuming I worked with meteorological observations and wanted to know not only the daily maximum value but also the relevant timestamp, describing when this value was observed, is it possible to ...
dimfalk's user avatar
  • 845
0 votes
1 answer
65 views

Right class for yearly / bi-annual data

I was wondering which class or column specification suits best for yearly or bi-annual data. So if I have a time variable in a dataframe which is looking like the following and I don't want it to be ...
Marie Veit's user avatar
0 votes
1 answer
12 views

How do I use the zoo package to convert Year.Quarter to a date?

My column with my date variables look like "2022.Q2" I would like to convert this into a numeric date using as.yearqtr but I keep getting an error on the format. as.Date(as.yearqtr(Year, ...
P.08's user avatar
  • 21
0 votes
0 answers
72 views

How to smooth a zoo series in R

I would like to smooth a zoo time series (a zoo object) in R. I've already performed the classic moving average smoothing, but I would like to try other methods, such as the kernel smoothing or others,...
DesperateWoman's user avatar
0 votes
2 answers
67 views

how to select every months first value and perform calculations in r

I have a dataframe df as follows: Date Value 1-Jun-12 5 2-Jun-12 10 3-Jun-12 8 4-Jun-12 15 2-Jul-12 12 3-Jul-12 6 4-Jul-12 14 1-Aug-12 20 2-...
Prad's user avatar
  • 339
0 votes
1 answer
68 views

Plot multiple columns saved in data frame with no x

My problem is multifaceted. I would like to plot multiple columns saved in a data frame. Those columns do not have an x variable but would essentially be 1 to 101 consistent for all. I have seen that ...
Edgar Garcia's user avatar
0 votes
0 answers
96 views

Is it possible to use the dtw() function on zoo objects?

I need to use the dtw() function of the dtw package on two time series of type zoo but I cannot. This is the error I get: in proxy::dist(x, y, method = dist.method) : x and y must be conform in ...
DesperateWoman's user avatar
0 votes
1 answer
118 views

RcppRoll roll_median na.rm = TRUE gives unexpected results

I am confused as to why roll_median(..., na.rm=TRUE) returns NA in the following reprex when there are 11 NA values, but returns a value when there are 10 NA values. Please note: The dplyr window ...
jmuhlenkamp's user avatar
  • 2,092
0 votes
1 answer
77 views

R/zoo: duplicate index entries in ‘order.by’ are not unique

I have an excel file containing 3 columns of data against a column of time at one hour interval. I tried to convert the data into a zoo object. But everytime i tried to that there is an error that ...
David Santiago Hernández's user avatar
1 vote
2 answers
73 views

zoo::rollapply generates an error when applying a function from another package to a column of a dataframe

Here's a miminal example: df_1 <- data. Frame( a = 1:10) I have no trouble computing a rolling mean on a using zoo::rollapply zoo::rollapply(df_1$a, 5, "mean", fill = NA, align = "...
Thomas Philips's user avatar
1 vote
1 answer
99 views

Applying filter using rollapply in R

DT <- data.table( N = 1:16, x = c(11,11,11,11,11,11,11,11,21,21,21,21,21,21,21,21), y = rep(1:4,4,4,4,1:4,4,4,4), z = c(53,71,27,64,43,62,61,85,44,56,23,37,31,48,80,38), min = c(2.74,2.77,2....
zainul abid's user avatar
1 vote
2 answers
68 views

How to remove all "xts" "zoo" object from R environment?

I need help on removing all "xts" "zoo" object from R (global)environment. I learned that I can remove dataframes by using the following: rm(list=ls(all=TRUE)[sapply(mget(ls(all=...
aik3e's user avatar
  • 121
0 votes
0 answers
16 views

Unit root test on lagged variables

guys! I'm using this sintaxe but when I use the last part ("modelo = ...") it shows the following: "Error in merge.zoo(difetanol, detanol, mes2, mes3, mes4, mes5, mes6, mes7, : all(...
Renata Benicio's user avatar
0 votes
1 answer
54 views

Filtering within summarise function in r or summing previous rows based on filter - Reprex

I'm trying to sum previous rows of data based on a filter of name_ex and a specified number of rounds. More specifically: Goal: To sum the previous 3 rows of stat1 and stat2 respectively. These sums ...
DonnyDolio's user avatar
1 vote
2 answers
187 views

Displaying labels on x-axis with "yearmon" variable (ggplot)

I am trying to display all month values on my x-axis, which is formatted as a "yearmon" variable My data are structured as follows: Print data example dput(collective_action_monthly[1:4, ]) ...
nesta1992's user avatar
  • 168
0 votes
1 answer
273 views

zoo + snapshot files are created very frequently

under folder - /var/hadoop/zookeeper/version-2/ we can see that Zookeeper transaction logs and snapshot files are created very frequently (multiple files in every minute) and that fills up the ...
Judy's user avatar
  • 1,445
0 votes
2 answers
133 views

Create column with rolling linear model coefficients

I need to perform a rolling linear regression of 24 months between a variable and time and save the B1 coefficient on a column. I can do the rolling regression but I don't know how to save the B1 ...
Andres Gonzalez's user avatar
1 vote
1 answer
69 views

R - using merge.zoo with a custom column name

I am using a for loop to iterate through a list of fund codes, make an API call and then combine this data in one large zoo object. I would like to see something like this (shortened version), where ...
James Ashwood's user avatar
3 votes
3 answers
208 views

Convert YearQtr series to End of the month Date

I am trying to convert a quarterly series of data in to monthly series in R. I can repeat the same quarterly data for each of the three months in the quarter. Not sure why as.yearmon gives out "...
Jain's user avatar
  • 939
1 vote
4 answers
87 views

How to do a partial autocorrelation plot with many zeros in r

I have a dataset of ER admissions with many zeros. These are daily admissions from 2016-06-05 to 2019-12-31. This is my data: df<-structure(list(date = structure(c(1465084800, 1465171200, ...
Lilia's user avatar
  • 109

1
2 3 4 5
27