Skip to content
Prev 303539 / 398503 Next

r data structures

It would be helpful to distinguish between a formal dimension attribute,
and a (personal) conceptual model of whether or not any particular R
object, or type of object, has dimension. Mention of data frames having
dimension can be found in the help page for the dim() function.
[1] TRUE
NULL
NULL
int [1:10] 1 2 3 4 5 6 7 8 9 10
[1] 10
[1] 2 5
$dim
[1] 2 5
int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10
[1] 10



The vector does not have a formal dimension ("dim") attribute, but the
matrix does.



Regarding data frames and lists:

##
## data frame
##
'data.frame':   3 obs. of  2 variables:
 $ a: int  1 2 3
 $ b: int  1 2 3
$names
[1] "a" "b"

$row.names
[1] 1 2 3

$class
[1] "data.frame"
[1] 3 2

##
## list
##
List of 2
 $ a: num 1
 $ b: chr "c"
$names
[1] "a" "b"
NULL
[1] 2

Conceptually, I would consider data frames to have two dimensions (rows
and columns). They do not have a formal "dim" attribute, but the dim()
function does return a value.

I personally do not think of lists as having dimension -- I never ask
myself, what is the dimension of a list? But I do often enquire as to the
length of a list, so might, if forced to, admit that lists have one
dimension, length. But I do not think it is helpful to think of lists as
having dimension. Certainly, lists do not have two dimensions.