Displaying 20 results from an estimated 10000 matches similar to: "Moving window per group"
2011 Apr 09
5
Yearly aggregates and matrices
Hi,
I need to perform calculations on subsets of a data frame:
DF = data.frame(read.table(textConnection(" A B C D E F
1 a 1995 0 4 1
2 a 1997 1 1 3
3 b 1995 3 7 0
4 b 1996 1 2 3
5 b 1997 1 2 3
6 b 1998 6 0 0
7 b 1999 3 7 0
8 c 1997 1 2 3
9 c 1998 1 2 3
10 c 1999 6 0 0
11 d 1999 3 7 0
12 e 1995 1 2 3
13 e 1998 1 2 3
14 e 1999 6
2011 Dec 02
2
Moving column averaging
# need zoo to use rollapply()
# your data (I called df)
df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L),
e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d",
"e", "f"), class = "data.frame", row.names = c(NA, -2L))
# transpose and make a zoo object
df2 <- zoo(t(df))
#rollapply to get
2011 Aug 12
2
rollapply.zoo() with na.rm=TRUE
Hi.
I'm comparing output from rollapply.zoo, as produced by two versions
of R and package zoo. I'm illustrating with an example from a R-help
posting 'Zoo - bug ???' dated 2010-07-13.
My question is not about the first version, or the questions raised in
that posting, because the behaviour is as documented. I'm puzzled as
to why na.rm no longer is passed to mean, i.e. why
2011 Jun 02
2
Counting occurrences in a moving window
Hi list, based on the following data.frame I would like to create a variable
that indicates the number of occurrences of A in the 3 years prior to the
current year:
DF = data.frame(read.table(textConnection(" A B
8025 1995
8026 1995
8029 1995
8026 1996
8025 1997
8026 1997
8025 1997
8027 1997
8026 1999
8027 1999
8028 1995
8029 1998
8025 1997
8027 1997
8026 1999
8027 1999
2011 Apr 03
1
zoo:rollapply by multiple grouping factors
# Hi there,
# I am trying to apply a function over a moving-window for a large
number of multivariate time-series that are grouped in a nested set of
factors. I have spent a few days searching for solutions with no luck,
so any suggestions are much appreciated.
# The data I have are for the abundance dynamics of multiple species
observed in multiple fixed plots at multiple sites. (I total I
2013 Jun 27
3
using "rollapply" to calculate a moving sum or running sum?
#using "rollapply" to calculate a moving sum or running sum?
#I am tryign to use rollapply to calcualte a moving sum? #I tried
rollapply and get the error message
#"Error in seq.default(start.at, NROW(data), by = by) :
# wrong sign in 'by' argument"
#example:
mymatrix <- ( matrix(data=1:100, nrow=5, ncol=20) )
mymatrix_cumsum <- ( matrix(data=NA, nrow=5,
2011 Apr 14
1
Create matrices for time series
Hi list, I would like to use the following data.frame to generate matrices
over a 3 year moving window:
DF = data.frame(read.table(textConnection(" A B C
80 8025 1995
80 8026 1995
80 8029 1995
81 8026 1996
82 8025 1997
82 8026 1997
83 8025 1997
83 8027 1997
84 8026 1999
84 8027 1999
85 8028 1995
85 8029 1998"),head=TRUE,stringsAsFactors=FALSE))
Function to be
2011 Nov 04
1
zoo performance regression noticed (1.6-5 is faster...)
Good morning,
I have discovered what I believe to be a performance regression
between Zoo 1.6x and Zoo 1.7-6 in the application of rollapply.
On zoo 1.6x, rollapply of my function over my data takes about 20
minutes. Using 1.7-6, the same code takes about 6 hours.
R --version
R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform:
2012 Jan 24
1
problems with rollapply {zoo}
Here is a relatively simple script (with comments as to the logic
interspersed):
# Some of these libraries are probably not needed here, but leaving them in
place harms nothing:
library(tseries)
library(xts)
library(quantmod)
library(fGarch)
library(fTrading)
library(ggplot2)
# Set the working directory, where the data file is located, and read the
raw data
2019 Oct 11
1
New matrix function
Also note that the functionality discussed could be regarded as a generalization
of matrix multiplication where * and + are general functions and in this case
we have * replaced by == and + replaced by &.
On Fri, Oct 11, 2019 at 10:46 AM Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
>
> Using the example in the link here are two one-liners:
>
> A <-
2010 Oct 28
4
Returning highs and lows in R
I'm having trouble returning a rolling n period highest value for a data
set. For each day I want to calculate the highest value over the last 3
days. I am using the following packages: zoo, xts, quantmod and TTR.
Thanks, Jason
GLD.Close
2010-10-01 128.91
2010-10-04 128.46
2010-10-05 130.99
2010-10-06 131.81
2010-10-07 130.37
2010-10-08 131.66
2010-10-11
2011 Mar 04
2
apply.rolling() to a multi column timeSeries
Hello there,
I am trying to compute the 3 months return momentum with the timeSeries x.ts,
which is just a subset of simple returns from a much bigger series,
> class(x.ts)
[1] "timeSeries"
attr(,"package")
[1] "timeSeries"
> dim(x.ts)
[1] 20 3
> x.ts[1:8,]
GMT
MS.US AAPL.US CA.FP
1996-01-31 0.15159065 -0.133391894
2013 Mar 13
1
Determining maximum hourly slope per day
Hello,
I have a challenge!
I have a large dataset with three columns, "date","temp", "location".
"date" is in the format %m/%d/%y %H:%M, with a "temp" recorded every 10
minutes. These temperatures of surface temperatures and so fluctuate during
the day, heating up and then cooling down, so the data is a series of peaks
and troughs. I would like
2009 Jul 07
1
Error in Rolling window of function - rollapply
Dear Colleagues,
I have faced with the problem that function rollaply with rolling window for
calculation of volatility doesn't give the all results of calculations.
I have run the rolling window for calculation in Excel and obtained that the
number of outputs for Excel is 36 and for R is 18. The total number of
observations is 37. In the attachment you can find pdf of the Excel and
Excel
2010 Sep 10
6
adding zeroes after old zeroes in a vector ??
Hello
Imagine I have a vector with ones and zeroes
I write it compactly:
1111111100001111111111110000000001111111111100101
I need to get a new vector replacing the "N" ones following the zeroes to
new zeroes.
For example for N = 3
1111111100001111111111110000000001111111111100101 becomes
1111111100000001111111110000000000001111111100000
I can do it with a for loop but I've read
2010 Jul 13
2
Zoo - bug ???
Hi folks,
I am confused whether the following is a bug or it is fine
Here is the explanation
a <- zoo(c(NA,1:9),1:10)
Now If I do
rollapply(a,FUN=mean,width=3,align="right")
I get
> rollapply(a,FUN=mean,width=3,align="right")
3 4 5 6 7 8 9 10
NA NA NA NA NA NA NA NA
But I shouldn't be getting NA right ? i.e for index 10 I should get
(1/3)*(9+8+7)
2010 Apr 09
3
"fill in" values between rollapply
Hi,
Sorry ahead of time for not including data with this question.
Using rollapply to calculate mean values for 5 day blocks, I'd use this:
Roll5mean <- rollapply(data, 5, mean, by=5, align = c("left"))
My question is, can someone tell me how to fill in the days between each of
these means with the previously calculated mean? If this doesn't make
sense, I will clarify and
2010 Oct 21
2
Calculating variances in a moving window
I am trying to create basic descriptive statistics for a spatial dataset
using moving windows of variable sizes.
I found the filter(dataset, rep(1/a,1)) very useful for obtaining
averages for a given moving window size "a"
(a is the window size within a column of data in a matrix - the filter
is applied to all columns automatically)
I could not find anything analogous for
2009 Mar 23
1
performance: zoo's rollapply() vs inline
zoo's rollapply() function appears to be extremely useful for plugging in a
function on-the-fly to run over a window. With inline, there is a lot more
coding and room for error, and the code is less portable because the user
has to have R compiling set up or it won't work.
However, rollapply() seems to be really slow. Several orders of magnitude
slower than inline, in fact. I don't
2011 Jun 07
1
Packages for R-CRAN (organizing aspects)
Hello,
I have some ideas for packages that I want to provide on R-CRAN.
One package alreads is working, but I have some warnings in
when compiling. Also I don't know if the libraries in use are only
working on Unix/Linux.
So I have some general questions:
- If I'm not sure if the code would also work on windows
(needing some ceratain libraries or tools),
would it be better to