Hi Steve, > It's not clear what you're having problems understanding. By > setting the "dim" attribute of your (1d) vector, you are changing > itsdimenensions.
I'm following An Introduction to R to learn R On 5.1 Arrays http://cran.r-project.org/doc/manuals/R-intro.html#Vectors-and-assignment It mentions:- ... For example if the dimension vector for an array, say a, is c(3,4,2) then there are 3 * 4 * 2 = 24 entries in a and the data vector holds them in the order a[1,1,1], a[2,1,1], ..., a[2,4,2], a[3,4,2]. I don't understand "on .... =24 entries in a and the data vector holds them in the order a[1,1,1], a[2,1,1], ..., a[2,4,2], a[3,4,2]." the order a[1,1,1], a[2,1,1], ..., a[2,4,2], a[3,4,2]? What does it mean "the order a[1,1,1], a[2,1,1], ..., a[2,4,2], a[3,4,2]"? Thanks B.R. Stephen ----- Original Message ---- From: Steve Lianoglou <mailinglist.honey...@gmail.com> To: Stephen Liu <sati...@yahoo.com> Cc: Gerrit Eichner <gerrit.eich...@math.uni-giessen.de>; r-help@r-project.org Sent: Fri, November 5, 2010 10:18:18 PM Subject: Re: [R] About 5.1 Arrays Hi, On Fri, Nov 5, 2010 at 6:00 AM, Stephen Liu <sati...@yahoo.com> wrote: [snip] >> A[i, j, k] is the value of the element in position (i,j,k) of array A. In >> other words, it is the entry in row i, column j, and "layer" k (if one >> wants to think of A as a cuboidal grid). > > Sorry I can't follow. Could you pls explain in more detail. > > e.g. > >> z <- 0:23 >> dim(z) <- c(3,4,2) >> dim(z) > [1] 3 4 2 > > >> z > , , 1 > > [,1] [,2] [,3] [,4] > [1,] 0 3 6 9 > [2,] 1 4 7 10 > [3,] 2 5 8 11 > > , , 2 > > [,1] [,2] [,3] [,4] > [1,] 12 15 18 21 > [2,] 13 16 19 22 > [3,] 14 17 20 23 It's not clear what you're having problems understanding. By setting the "dim" attribute of your (1d) vector, you are changing its dimenensions. ## This is a 1d vector R> x <- 1:12 R> x ## I can change it into 2d (like a matrix), let's do 2 rows, 6 columns R> dim(x) <- c(2,6) R> [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 3 5 7 9 11 [2,] 2 4 6 8 10 12 If you understand that using three numbers to set the dimension means you are making a 3d matrix R> dim(x) <- c(2,3,2) But the problem is you can't draw 3d in a terminal, so it just draws the third dimension in order R> x x , , 1 [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 , , 2 [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12 ### Imagine this as a cube: ,,1 is the front layer, ,,2 is the back layer. Just chew on it for a minute, it'll make sense. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ R-help@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.