to.matrix attempts to convert any data to a row matrix. In particular, data frames are converted by as.matrix, (numeric) vectors are converted to a single row/column matrix, according to the rowMatrix argument.

to.matrix(x, rowMatrix = TRUE)

Arguments

x

data to convert to a matrix

rowMatrix

if TRUE, numeric vectors are converted to a single row matrix, if FALSE, they get converted to a single column matrix

Value

matrix

Examples

to.matrix(1:3)
#> [,1] [,2] [,3] #> [1,] 1 2 3
to.matrix(1:3,rowMatrix=FALSE)
#> [,1] #> [1,] 1 #> [2,] 2 #> [3,] 3
to.matrix(iris[1:3,1:4])
#> Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3.0 1.4 0.2 #> 3 4.7 3.2 1.3 0.2
to.matrix(matrix(1:4,2))
#> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4