I ran the following in R and received the same output for both matrix()
and as.matrix()
and now I am not sure what the difference between them is:
matrix
constructs a matrix from its first argument, with a given number of rows and columns. If the supplied object isn't large enough for the desired output, matrix
will recycle its elements: for example, matrix(1:2), nrow=3, ncol=4)
. Conversely, if the object is too big, then the surplus elements will be dropped: for example, matrix(1:20, nrow=3, ncol=4)
.
as.matrix
converts its first argument into a matrix, the dimensions of which will be inferred from the input.