Simplify matrix in case of single row/columns

simplifyMatrix(matrix)

Arguments

matrix

A matrix of any dimension

If only one row/column is present, the dimension is dropped and a vector will be returned

Examples

testMatrix <- matrix(round(rnorm(9),2), nrow=3)
simplifyMatrix(testMatrix)
#>       [,1]  [,2] [,3]
#> [1,]  0.85  0.78 0.46
#> [2,] -0.22 -0.66 0.90
#> [3,]  1.08  0.19 0.25
simplifyMatrix(testMatrix[1L,,drop=FALSE])
#> [1] 0.85 0.78 0.46
simplifyMatrix(testMatrix[,1L,drop=FALSE])
#> [1]  0.85 -0.22  1.08