[R] About 5.1 Arrays

Stephen Liu satimis at yahoo.com
Fri Nov 5 09:22:39 CET 2010


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






More information about the R-help mailing list