R-alpha: is.vector of one-dimensional array

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 5 Dec 1997 18:24:25 +0100


>>>>> "PaulG" == Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:

    >> is.vector() of an one-dimensional array returns FALSE. this is also
    >> the behavior of Splus, but totally counter-intuitive for me ... IMO
    >> an array of dimension 1 is exactly the definition of a vector ...
not quite exactly.

I think we have agreed that 
	vector
and
	array
are mutually exclusive [i.e., their is.XXX test], 
and actually, the distinction arising by  is.null(dim(.)).


    PaulG> I assume by "one-dimensional array" you mean a two or higher
    PaulG> dimensional array with all but one of the values from dim(x)
    PaulG> being 1.
No, he meant the `rare' thing which table(.) produces 
	-- both in R and S -- 
which has  length(dim(.)) == 1:

> ta <- table(rpois(20,4))
> dim(ta)
[1] 9
> ta
0 1 2 3 4 5 6 7 8 
1 2 4 3 4 2 2 1 1 
> str(ta)
 int [, 1:9] 1 2 4 3 4 2 2 1 1
 - attr(*, "dimnames")=List of 1
  ..$ : chr [1:9] "0" "1" "2" "3" "4" "5" "6" "7" "8"
> 

    PaulG> This is possibly counter-intuitive, but there are cases
    PaulG> where one needs to distinguish these.  Perhaps length(dim(x))
    PaulG> would be better, but dim returns NULL for a vector. This is even
    PaulG> more counter-intuitive to me. I think it should return length(x)
    PaulG> for a vector. In any case there is lots of code out there that
    PaulG> will break if you change these.

Yes! - and we `must' live with these, I think.

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._