Search code examples
rmatrixdimensions

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))?


Solution

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