Dear all, I have a large dataset which I hope to reduce in size, to make it more useable. I hope to do this by taking an average of each 60 x 60 blockof values and forming a new data frame out of the averaged values. How would I go about taking averages of 60 x 60 'blocks' in R, and cycling through the whole dataset, recording each calculated value in a new table/data frame? Many thanks for any advice offered. Steve
On Sun, Sep 7, 2008 at 12:32 PM, Steve Murray <smurray444 at hotmail.com> wrote:> > > Dear all, > > I have a large dataset which I hope to reduce in size, to make it more useable. I hope to do this by taking an average of each 60 x 60 blockof values and forming a new data frame out of the averaged values.what does the data look like? vector / matrix / list ?> > How would I go about taking averages of 60 x 60 'blocks' in R, and cycling through the whole dataset, recording each calculated value in a new table/data frame?some form of apply(), tapply(), mapply(), or lapply() would probably do what you want> Many thanks for any advice offered. > > Steve >Here is a start: # step 1. too much data: 10x10 matrix m <- matrix(runif(100), ncol=10) # step 2. reduce down to a 10x1 vector, averaging-by-row: apply(m, 1, mean) # step 3 profit. Dylan
This was answered last month: http://tolstoy.newcastle.edu.au/R/e4/help/08/08/19091.html On Sun, Sep 7, 2008 at 3:32 PM, Steve Murray <smurray444 at hotmail.com> wrote:> > > Dear all, > > I have a large dataset which I hope to reduce in size, to make it more useable. I hope to do this by taking an average of each 60 x 60 blockof values and forming a new data frame out of the averaged values. > > How would I go about taking averages of 60 x 60 'blocks' in R, and cycling through the whole dataset, recording each calculated value in a new table/data frame? > > Many thanks for any advice offered. > > Steve > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Hi Steve, You probably want to check out ?by or ?aggregate, maybe using (rownames(df) %/% 60) : (colnames(df) %/% 60) as your index variable. --Adam On Sun, 7 Sep 2008, Steve Murray wrote:> > > Dear all, > > I have a large dataset which I hope to reduce in size, to make it more > useable. I hope to do this by taking an average of each 60 x 60 blockof > values and forming a new data frame out of the averaged values. > > How would I go about taking averages of 60 x 60 'blocks' in R, and cycling > through the whole dataset, recording each calculated value in a new > table/data frame? > > Many thanks for any advice offered. > > Steve > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >