Skip to contents

This functions tries to replicate the behavior of the base function "size" in Matlab

Usage

size(x, d)

Arguments

x

object to be evaluated

d

dimension of object to be evaluated

Value

A vector whose size is the number of dimensions of x and whose scale corresponds to the number of elements on (i.e. the size of) each dimension.

Note

On MATLAB, size(1, 100) returns 1. As a matter of fact, if the user calls for a dimension which x doesn't have size() always returns 1. R's default behavior is more reasonable in those cases (i.e., returning NA), but since the point of this function is to replicate MATLAB behaviors (bugs and questionable behaviors included), this function also does this.

Examples

size(10)
#> [1] 1
size(1:4)
#> [1] 1 4
size(matrix(1:6, 2))
#> [1] 2 3
size(array(1:24, c(2, 3, 4)))
#> [1] 2 3 4