Gabor == Gabor Grothendieck [EMAIL PROTECTED]
on Tue, 10 Jan 2006 14:47:57 -0500 writes:
Gabor If its just succint you are after then this is slightly
Gabor shorter:
Gabor identical(dim(x)+0, c(3,5))
indeed, or, less succinct, but maybe more readable (and along the
top-level
Dear R Users,
I want to test the dimensions of an incoming vector, matrix or array safely
and succinctly. Specifically I want to check if the unknown object has
exactly 2 dimensions with a specified number of rows and columns.
I thought that the following would work:
you could use: isTRUE(all.equal(dim(obj), c(3, 5)))
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web:
Gregory == Gregory Jefferis [EMAIL PROTECTED]
on Tue, 10 Jan 2006 14:47:43 + writes:
Gregory Dear R Users,
Gregory I want to test the dimensions of an incoming
Gregory vector, matrix or array safely
Gregory and succinctly. Specifically I want to check if
Thanks for suggestions. This is a simple question in principle, but there
seem to be some wrinkles - I am always having to think quite carefully about
how to test for equality in R. I should also have said that I would like
the check to be efficient as well safe and succinct.
One suggestion
If its just succint you are after then this is slightly
shorter:
identical(dim(x)+0, c(3,5))
On 1/10/06, Gregory Jefferis [EMAIL PROTECTED] wrote:
Thanks for suggestions. This is a simple question in principle, but there
seem to be some wrinkles - I am always having to think quite
There's a gotcha in using identical() to compare dimensions -- it also
compares names, e.g.:
x - array(1:14, dim=c(rows=3,cols=5))
dim(x)
rows cols
35
identical(dim(x)+0, c(3,5))
[1] FALSE
identical(as.numeric(dim(x)+0), c(3,5))
[1] TRUE
Gabor Grothendieck wrote:
If its just