Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare dimension of two matrices in R

Having two matrices, x and y, how may I check if their dimensions match?

I though about comparisons like

if(nrow(x) == nrow(y) && ncol(x) == ncol(y)) { ... }

or

if(min(dim(x) == dim(y)) == 1) { ... }

but this doesn't seem quite straigth forward.

Question: Is there a single function / single command for matrices to check if they have the same dimension (something like sameDim(x,y))?

like image 938
Markus Weninger Avatar asked Dec 13 '25 09:12

Markus Weninger


1 Answers

As suggested by @eipi10, I now use identical(dim(x), dim(y)).

like image 78
Markus Weninger Avatar answered Dec 16 '25 23:12

Markus Weninger