[R] how to resample (or resize) matrix?

2006-07-27 Thread Vladimir Eremeev
Dear r-help, I have a matrix, suppose, 10x10, and I need the matrix 5x5, having in each cell a mean value of the cells from the initial matrix. Please, point me to a function in R, which can help me doing that. Digging the documentation and mail archives didn't give me a result.

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread jim holtman
Is this what you want: the mean of the surrounding 4 cells? x - matrix(1:100, 10) # create data rmean - matrix(0,5,5) # result matrix for (i in 1:5){ + for (j in 1:5){ + rmean[i, j] - mean(x[c(-1,0) + 2 * i, c(-1,0) + 2 * j]) + } + } x [,1] [,2] [,3] [,4] [,5] [,6]

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread Robin Hankin
Right, I think I understand the question. library(magic) ?subsums If you want a windowed moving average, do: x - matrix(1:100,10,10) subsums(x,6,FUN=mean,pad=NA,wrap=F)[6:10,6:10] If you want block average, do: subsums(x,2,FUN=mean,pad=NA,wrap=F)[seq(2,10,2),seq(2,10,2)] which agrees

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread Gabor Grothendieck
Assuming the problem is to partition the 10x10 matrix x into 25 two by two squares and then average each of those squares, try this: apply(array(x, c(2,5,2,5)), c(2,4), mean) On 7/27/06, Vladimir Eremeev [EMAIL PROTECTED] wrote: Dear r-help, I have a matrix, suppose, 10x10, and I need the

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread Vladimir Eremeev
Dear jim, Yes. But, unfortunately, two nested for loops will execute very slow. It is not very serious problem to do my task with an image processing package, I am wondering if it is efficiently possible with R. Thursday, July 27, 2006, 2:20:13 PM, you wrote: jh Is this what you want: the mean

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread Vladimir Eremeev
Dear Robin, Thank you, seems it is what I need. --- Best regards, Vladimirmailto:[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] how to resample (or resize) matrix?

2006-07-27 Thread Vladimir Eremeev
Dear Sean, Thursday, July 27, 2006, 3:31:31 PM, you wrote: SOR Hi Vladimir, SOR I was wondering whether this was image related :-) Yes, that's right, I am doing image processing with R. SOR would one of the image related libraries do it for you? SOR looking at SOR