similar to: running mean in blocks

Displaying 20 results from an estimated 30000 matches similar to: "running mean in blocks"

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
2006 Aug 16
3
separate row averages for different parts of an array
I have an array with 44800 columns and 24 rows I would like to compute the row average for the array 100 columns at a time, so I would like to end up with an array of 24 rows x 448 columns. I have tried using apply(dataset, 1, function(x) mean(x[])), but I am not sure how to get it to take the average 100 columns at a time. Any ideas would be welcomed. thanks, Spencer [[alternative HTML
2018 Mar 25
3
Take average of previous weeks
Dear all, I have weekly data by city (variable citycode). I would like to take the average of the previous two, three, four weeks (without the current week) of the variable called value. This is what I have tried to compute the average of the two previous weeks; df = df %>% mutate(value.lag1 = lag(value, n = 1)) %>% mutate(value .2.previous = rollapply(data = value.lag1,
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 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
2012 Jul 08
3
How to replace a column in a data frame with another one with a different size
Hello everyone, I have a dataframe with 1 column and I'd like to 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)]
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)
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
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
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
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
2008 Aug 21
1
max and min with the indexes in a zoo object (or anything else that could solve the problem)
library(zoo) library(chron) t1 <- chron("1/1/2006", "00:00:00") t2 <- chron("1/31/2006", "23:45:00") deltat <- times("00:15:00") tt <- seq(t1, t2, by = times("00:15:00")) d <- sample(33:700, 2976, replace=TRUE) sin.zoo <- zoo(d,tt) #there are ninety six reading in a day d.max <- rollapply(sin.zoo, width=96, FUN=max)
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
2007 Dec 10
1
moving average and NA values
The S-plus function moving.ave(data, span = 2) calculates the moving average, but it does not have an argument to tell it how to deal with NA values, so it will return NA for all averages as shown below. Is there an R or S moving average function which is able to omit some NA values in the dataset? In the simple sample shown below it would be possible to just remove the rows with NA values. The
2011 Nov 01
1
Multiple time series with zoo
Thanks for everyone's input so far, it is greatly appreciated. But I've got one last task I could use some advice on Here are the first few lines of my data set: site,time_local,time_utc,reef_type_code,sensor_type,sensor_depth_m,temperature_c 06,2006-04-09 10:20:00,2006-04-09 20:20:00,BAK,sb39, 2, 29.63 06,2006-04-09 10:40:00,2006-04-09 20:40:00,BAK,sb39, 2, 29.56 06,2006-04-09
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
2012 Oct 16
2
sliding window analysis with rollapply
Dear List members I want to do the sliding window 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,
2011 Mar 10
1
Moving window per group
Hi, I have a data.frame of the following type: F = data.frame(read.table(textConnection(" A B 1 1 4 2 1 3 3 1 1 4 1 4 5 1 2 6 1 2 7 1 2 8 2 1 9 2 1 10 2 1 11 2 1 12 3 2 13 3 4 14 3 1 15 3 1 16 3 1"),head=TRUE,stringsAsFactors=FALSE)) F A B 1 1 4 2 1 3 3 1 1 4 1 4 5 1 2 6 1 2 7 1 2 8 2 1 9 2 1 10 2 1 11 2 1 12 3 2 13 3 4 14 3 1 15 3 1 16 3 1
2009 Nov 27
2
How to compute Rolling analysis of Standard Deviation using ZOO package?
Hello: I want to get a rolling estimation of the stdev of my data. Searching the document, I found the function "rollapply" in the zoo package. For example, my series is "c", and i want get a period of 10 days, so i write the command below: roll.sd = rollapply( c, 10, sd, na.pad = TRUE, align = 'right' ) but there is an error in it ,and the computing cannot be
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