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.67 0.68 -1.41 #> [2,] 0.46 -0.55 -0.19 #> [3,] -0.05 -2.02 1.09
simplifyMatrix(testMatrix[1L,,drop=FALSE])
#> [1] 0.67 0.68 -1.41
simplifyMatrix(testMatrix[,1L,drop=FALSE])
#> [1] 0.67 0.46 -0.05