Skip to content
Prev 31032 / 63424 Next

x <- 1:2; dim(x) <- 2? A vector or not?

What you have is a one-dimensional array: they crop up in R most often 
from table() in my experience.
'table' int [, 1:10] 2 6 18 21 13 16 13 4 3 4
  - attr(*, "dimnames")=List of 1
   ..$ : chr [1:10] "0" "1" "2" "3" ...

and yes, f is an atmoic vector and yes, str()'s notation is confusing 
here but if it did [1:10] you would not know it was an array.  I 
recall discussing this with Martin Maechler (str's author) last 
century, and I've just checked that R 2.0.0 did the same.

The place in which one-dimensional arrays differ from normal vectors 
is how names are handled: notice that my example has dimnames not 
names, and ?names says

      For a one-dimensional array the 'names' attribute really is
      'dimnames[[1]]'.

I think these days we have enough internal glue in place that an end 
user would not notice the difference (but those working at C level 
with R objects may need to know).
On Mon, 12 Jan 2009, Henrik Bengtsson wrote: