Re: [R] Splitting 3D matrix from for loop to generate/save 2D matrices

2010-11-21 Thread David Winsemius
On Nov 22, 2010, at 12:27 AM, Hana Lee wrote: Hi! I have a matrix called M with dimension (586,100,100). In R you have an array (not a matrix) wehn the number of dimensions is 3. I would like to split and save this into 586 matrices with dimension 100 by 100. I have tried the followi

Re: [R] Splitting 3D matrix from for loop to generate/save 2D matrices

2010-11-21 Thread Henrik Bengtsson
Sorry, I did a mistake corrected below. On Sun, Nov 21, 2010 at 9:50 PM, hb wrote: > Hi, > > On Sun, Nov 21, 2010 at 9:27 PM, Hana Lee wrote: >> Hi! >> >> I have a matrix called M with dimension (586,100,100). > > First of all, In R it is only an object with *two* dimensions that is called > "m

Re: [R] Splitting 3D matrix from for loop to generate/save 2D matrices

2010-11-21 Thread Michael Bedward
Hi Hana, Use the paste function to create your file names. for ( i in 1:dim(M)[1] ) save( M[i,,], file=paste("M_", i, ".img", sep="") ) Alternatively, use the sprintf function to get names with leading zeroes for easier sorting of files: for (i in 1:dim(M)[1] ) save( M[i,,], file=sprintf("M_%03

Re: [R] Splitting 3D matrix from for loop to generate/save 2D matrices

2010-11-21 Thread Henrik Bengtsson
Hi, On Sun, Nov 21, 2010 at 9:27 PM, Hana Lee wrote: > Hi! > > I have a matrix called M with dimension (586,100,100). First of all, In R it is only an object with *two* dimensions that is called "matrix". Anything with two or more dimensions is called an "array". Example: > x <- 1:(2*3*4) > y