[R] Data.frame Vs Matrix Vs Array: Definitions Please
ggrothendieck at gmail.com
Wed Oct 27 15:45:20 CEST 2010
On Wed, Oct 27, 2010 at 8:38 AM, Ivan Calandra
<ivan.calandra at uni-hamburg.de> wrote:
> What I don't understand is why vectors (with more than one value) don't have
> dimensions. They look like they do have 1 dimension. For me no dimension
> would be a scalar. Like in geometry: a point has no dimension, a line has 1,
> a square has 2, a cube 3 and so on. Is it because of some internal process?
> The intuitive geometry way of thinking is not programmatically relevant?
Maybe you used APL before. The basic structure in that language is
an array but that is not the case for R. The basic structure for data
is a vector and more complex data objects are build from that. An
array is a more complex object than a vector. A 1d array is not the
same as a vector. Dimensions are an additional concept unlike APL.
>>> I would also add these:
>>> - the components of a vector have to be of the same mode (character,
>>> numeric, integer...)
>> however, a list with no attributes is a vector too so this is a vector:
>> > vl<- list(sin, 3, "a")
>> > is.vector(vl)
>>  TRUE
>> A vector may not have attributes so arrays and factors are not vectors
>> although they are composed from vectors.
> That's also completely unexpected for me! What is then a vector?! And then
> the difference between a vector and a list?! I mean, in practice, it's not
> so important, my understanding is probably enough for what I'm doing in R,
> but I'd like to understand how it works.
A list is really a vector of pointers so the components are of the
same type. Its just that you can't access the pointer nature of the
components. For example, you can have a matrix based on a list. We
have added a dimension to the list so it becomes an array even though
its based on a list:
> m <- matrix(list(sin, "a", 1, list(1:3)), 2, 2)
structure(list(.Primitive("sin"), "a", 1, list(1:3)), .Dim = c(2L,
[1,] ? 1
[2,] "a" List,1
> Also you wrote that a vector may not have attributes. I might be wrong (and
> certainly am), but aren't names attributes? So with is a named list still a
> my.list <- list(num=1:3, let=LETTERS[1:2])
>  "num" "let"
>  TRUE
names don't count. Neither does class.
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help