Hi folks, (Learning R) 5.1 Arrays http://cran.r-project.org/doc/manuals/R-intro.html#Vectors-and-assignment 1) If continued on previous example (3.1 Intrinsic attributes: mode and length),> z <- 0:9 > dim(z) <- c(3,5,100)Error in dim(z) <- c(3, 5, 100) : dims [product 1500] do not match the length of object [10] failed. 2) Ran;> z <- 0:1499 > dim(z) <- c(3,5,100) > dim(z)[1] 3 5 100 It worked OR 3)> z <- 1:1500 > dim(z) <- c(3,5,100) > dim(z)[1] 3 5 100 It also worked.> z[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ..... [1485] 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 [1499] 1499 1500 "0" is counted as 1 object. Does "object length" mean the total number of objects/entries? Please help me to understand follow; "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; a[1,1,1], a[2,1,1], ..., a[2,4,2] 1 * 1 * 1 / 2 * 1 * 1 / 2 * 4 * 2 is NOT 24 ? TIA B.R. Stephen L
On Fri, 5 Nov 2010, Stephen Liu wrote: [snip]> "0" is counted as 1 object.Of course! It is a number like any other.> Does "object length" mean the total number of objects/entries?Yes.> Please help me to understand follow; > > "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; > a[1,1,1], a[2,1,1], ..., a[2,4,2][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). Hth -- Gerrit --------------------------------------------------------------------- AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner
Hi Stephan Since early in November you have posted queries on R-help on 5 different topics as you are trying to learn to use R. This is a good thing, and many contributors to R-help have replied, taking pains to provide explanations and examples to be helpful. But, in return, it doesn't appear that you've done very much work on your own to help your understanding of arrays in R, since you keep posting follow-ups on aspects that had been explained before. This list is r-help, not r-tutor or r-you-do-my-thinking-for-me. On 11/5/2010 4:22 AM, Stephen Liu wrote:> Hi folks, > > (Learning R) > > 5.1 Arrays > http://cran.r-project.org/doc/manuals/R-intro.html#Vectors-and-assignment > > 1) > If continued on previous example (3.1 Intrinsic attributes: mode and length), > >> z<- 0:9 >> dim(z)<- c(3,5,100) > Error in dim(z)<- c(3, 5, 100) : > dims [product 1500] do not match the length of object [10] > > failed.Error messages in R are brief, and sometimes obscure, but what did you not understand from that error message? Cancel that. I don't want to know.> > 2) > Ran; > >> z<- 0:1499 >> dim(z)<- c(3,5,100) >> dim(z) > [1] 3 5 100 > > It worked > > > OR > > 3) >> z<- 1:1500 >> dim(z)<- c(3,5,100) >> dim(z) > [1] 3 5 100 > > It also worked. > >> z > [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 > [15] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 > ..... > [1485] 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 > [1499] 1499 1500 > > "0" is counted as 1 object. > > > Does "object length" mean the total number of objects/entries? > > > Please help me to understand follow; > > "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; > a[1,1,1], a[2,1,1], ..., a[2,4,2] > > 1 * 1 * 1 / 2 * 1 * 1 / 2 * 4 * 2 is NOT 24 ? > > TIA > > B.R. > Stephen L > > > >