search for: rollapply

Displaying 20 results from an estimated 122 matches for "rollapply".

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...
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 re...
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...
2010 Jan 13
1
Rollapply
Hi I would like to understand how to extend the function (FUN) I am using in rollapply below. ###################################### With the following simplified data, test1 yields parameters for a rolling regression data = data.frame(Xvar=c(70.67,70.54,69.87,69.51,70.69,72.66,72.65,73.36), Yvar =c(78.01,77.07,77.35,76.72,77.49,78.70,77.78,79.58)) data.z = zoo(d) t...
2008 Jul 31
1
rollapply() to portions of a matrix
Hi everyone, I have a rollapply statement that applies a function, in steps, over a data matrix as follows: #Code start testm<-rollapply(mat, 100, by=100, min, na.rm=F) #Code end This moves down matrix 'mat' and calculates the minimum value over a 100 row range, every 100 rows (i.e. no overlaps). NAs are not removed....
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...
2009 Jul 07
1
Error in Rolling window of function - rollapply
...nd 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 file. Below you can find my commands in R. > Ret<-read.csv("data.csv") > Ret_1<-zoo((Ret)) > Ret_2<-rollapply(Ret_1,20,sd) > Volatility_20<-sd(Ret_2) > Volatility_20 Data 0.03802453 > Ret_2 Data 10 0.9170356 11 0.9147269 12 0.8982093 13 0.9169873 14 0.9156607 15 0.8961262 16 0.9615083 17 0.9804045 18 0.9853978 19 0.9888628 20 0.8798952 21 0.8408839 22 0.9429053 23 0.9498478 24 0.9...
2009 Jun 19
1
function rollapply
Hi, I faced with problem when start using function - rollapply(returns, 3 , mean) Error in UseMethod("rollapply") : No suitable Method for "rollaply" How can I fix the problem? Thank you for help. -- Best regards, Andy Fetsun [[alternative HTML version deleted]]
2012 Oct 26
1
rollapply() by time, not entries (width)
Hi all- Thank you for reading my post. Please bear in mind that I'm very much a newbie with R! My question is this: I'm trying to use rollapply() on an irregular time series so I can't simply use the width parameter (I don't think). Rather than last 5 entries, I'd like to rollapply on last 6 months (for example). What would be the proper course of action for this? Thanks! -J -- View this message in context: http://r.789695...
2011 Apr 03
1
zoo:rollapply by multiple grouping factors
...# Let the function I want to apply over a right-aligned window of w=2 time steps be: cv<-function(x){sd(x)/mean(x)} w<-2 # The final output I want would look something like this: Out<-data.frame(dat,CV=round(c(NA,NA,runif(6,0,1),c(NA,NA,runif(6,0,1))),2)) # I could reshape and apply zoo:rollapply() to a given plot at a given site, and reshape again as follows: library(zoo) a<-subset(dat,Site==1&Plot==1) b<-reshape(a[-c(1,2)],v.names='Count',idvar='Time',timevar='Sp',direction='wide') d<-zoo(b[,-1],b[,1]) d out<-rollapply(d, w, cv, na.pad=T, a...
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)) # tr...
2012 Jul 08
3
How to replace a column in a data frame with another one with a different size
...replace that column with a moving average. Example: > library('zoo') > mydat <- seq_len(10) > mydat [1] 1 2 3 4 5 6 7 8 9 10 > df <- data.frame("V1" = mydat) > df V1 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 > df[df$V1 <- rollapply(df$V1, 3, mean)] Error in `$<-.data.frame`(`*tmp*`, "V1", value = c(2, 3, 4, 5, 6, 7, 8, : replacement has 8 rows, data has 10 > I could use a temporary variable to store the results of rollapply() and then reconstruct the data frame, but I was wondering if there is a one-liner...
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) Similarly > rollapply(a,FUN=mean,width=3) 2 3...
2012 Jan 24
1
problems with rollapply {zoo}
...en as: rFun <- function(d) { d$rt <- seq(1-nrow(d),0) polyfit <- lm(Close ~ poly(rt,4),d) p <- coef(polyfit) pr <- polyroot(c(p[2],2*p[3],3*p[4],4*p[5])) dd <- function(x) { rv = 2*p[3]+6*p[4]*x+12*p[5]*x*x;rv;} r <- dd(pr[1]) r } And I try to get rollapply to execute it on a moving window, I get errors. E.g. > rollapply(as.zoo(alpha),60,rFun) Error in from:to : argument of length 0 Yet, the following works: rollapply(alpha$Close,60,mean) what do I have to do to either my function or my use of rollapply in order to get it to work?...
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
2007 Nov 30
1
rollapply on zoo object
...size <- data.row[,small] out <- list(num.of.firms = length(data.row), big = big, small = small, big.size = big.size, small.size = small.size) } I want to apply the function on size_june, which hopefully gives me the portfolio groups (big and small) every June. But the "rollapply" complains as below > rollapply(size_june, width=1, size.portfolio, by.column=F) error message about : data.row[, !is.na(data.row)] : wrong dimension So I end up using the for-loop, which produces the outcome I wanted. Good! No problem! But a little uneasy about using for-loop. > out...
2006 Oct 03
2
maybe use voronoi.findrejectsites?
hi all members, please, i need you help... now a i´m working with veronoi polygons in a area with projections, but i need cut the polygons left. On other words, i need cut the polygons in the worked area. R help say that use the command voronoi.findrejectsites, but in this command i need put the numbers, any way...this command not cut!! do you can help me? Thank you for help me! José Bustos
2012 Jul 10
1
Help with vectors and rollapply
Hello I have a vector a =(-2,0,0,0,1,0,0,3,0,0,-4) I want to replace all zeros into previous non-zero state. So for instance the above vector should be converted into: a= (-2,-2,-2,-2,1,1,1,3,3,3,-4) I tried many things and finally concluded that probably(?) rollapply may be the best way? I tried f= function(x){ ifelse(x==0,Lag(x),x) } And then, rollappy(a,1,f) and that didn't work. Can someone help please? Thx R Jefferies archives and monitors outgoing and incoming e-mail. The contents of this email, including any attachments, are confi...
2010 Apr 02
1
All sub-summands of a vector
Hello, I'd like to take all possible sub-summands of a vector in the quickest and most efficient way possible. By "sub-summands" I mean for each sub-vector, take its sum. Which is to say: if I had the vector x<-1:4 I'd want the "sum" of x[1], x[2], etc. And then the sum of x[1:2], x[2:3], etc. And then...so on. The result would be: 1 2 3 4 2 5 7 6 9 10 I can
2012 Oct 16
2
sliding window analysis with rollapply
...ndow analysis of some specific values. Here is my code: require(zoo) dat <- read.table("chr1.txt", header = TRUE, sep="\t") dat2 <- cbind(dat[1,3]) #The first column is also important. It represents the position of the site on the chromosome. TS <- zoo(c(dat2)) a <- rollapply(TS, width=1000000, by=200000, FUN=mean, align="left") #The third column values should roll against the first column values. I might be wrong here with the code. plot1 <- plot.default(a, col="red", type="l") #It returns me some errors for this command. Error in plot...