[R] About 5.1 Arrays

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Nov 5 16:29:17 CET 2010


Hi,

On Fri, Nov 5, 2010 at 10:56 AM, Stephen Liu <satimis at yahoo.com> wrote:
> 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]"?

Let's just stick with a 2d matrix -- it's easier to think about.

I'm not sure if you are coming from a different programming language
or not, so perhaps this isn't helpful if you don't, but you might
imagine holding data for a 2d matrix in an 'array of arrays'
structure.

R doesn't do this. It holds the data for a 1d, 2d, 3d, ... 10d array
in a 1d vector. The data is stored in "column major" format, so the
rows of a 2d matrix are filled first.

If I have a 2d matrix like this:

1   2   3   4
5   6   7   8

R holds this in a 1d vector/array that looks like this:

1, 5, 2, 6, 3, 7, 4, 8

This idea follows through to higher dimensions.

Hope that helps,

-steve
-- 
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



More information about the R-help mailing list