Skip to content
Prev 30487 / 63424 Next

is.matrix

Daniel H?yer Iversen wrote:
All of the above is consistent with the documentation for is.matrix():

|  is.matrix| returns |TRUE| if |x| is a matrix and has a |dim 
<dim.html>| attribute of length 2) and |FALSE| otherwise

[There seems to be a typo in this sentence from ?is.matrix : an 
unmatched ")"]

This is also useful behavior -- when programming it is often useful to 
know whether something is a matrix or not because that can affect 
computations performed with the object.

For the more informal definition of "matrix" that it looks like want, 
you could use
 is.matrix(x) && all(dim(x)>1)
(or maybe all(dim(x) != 1) depending on how you want to treat matrices 
that have a dimension with zero extent)

-- Tony Plate