Re: [R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Bert Gunter
?? Petr's solution is shorter and for large problems considerably faster... -- Bert On Wed, Mar 14, 2012 at 2:08 AM, Tsjerk Wassenaar wrote: > Hi Lazarus, > > Sorry for my brevity before. I sent it from a phone. > > # Generate dummy data matrix > x <- matrix(1:100,nrow=5) > > # Rearrange into ar

Re: [R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Tsjerk Wassenaar
Hi Lazarus, You should use apply, not sapply. > a =matrix(1:12, nrow=2,ncol=6,byrow=TRUE) > b = array(a,c(2,2,3));b > colMeans(b) > > f1=function(x) sum(x)/length(row(a.df[,1:2])) > y3 <- apply(b, 1, f1) > > It only gives one matrix with only two values, I expected 3 values. To apply the functio

Re: [R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Tsjerk Wassenaar
Hi Lazarus, Sorry for my brevity before. I sent it from a phone. # Generate dummy data matrix x <- matrix(1:100,nrow=5) # Rearrange into array; ten groups of two columns y <- array(x,c(5,2,10)) # Average columns for each submatrix apply(y,c(1,3),mean) # Average per submatrix apply(y,3,mean) H

Re: [R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Petr Savicky
On Wed, Mar 14, 2012 at 03:22:39AM -0400, Lazarus Mramba wrote: > Dear all, > > I have a large matrix with about 2500 variables, and 100 rows. > > I would like to calculate the means of the every 10 variables starting from > 1:2500 and saving the results as a vector or matrix. > How can I do tha

Re: [R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Tsjerk Wassenaar
Hi Lazarus, Checkout arrays (?array). You can cast your matrix to an array of submatrices, and calculate the means per block using apply. Cheers, Tsjerk On Mar 14, 2012 9:25 AM, "Lazarus Mramba" wrote: Dear all, I have a large matrix with about 2500 variables, and 100 rows. I would like to

[R] Creating 250 submatrices from a large single matrix with 2500 variables using loops

2012-03-14 Thread Lazarus Mramba
Dear all, I have a large matrix with about 2500 variables, and 100 rows. I would like to calculate the means of the every 10 variables starting from 1:2500 and saving the results as a vector or matrix. How can I do that? Alternatively, How can I create 250 subset matrices in the order of variabl