A function factory to read matrix with given number of columns from a file.
The matrix is read row-wise (with byrow = TRUE
).
read_matrix(ncol)
ncol | integer, expected number of columns, passed to |
---|
function with 1 argument: file
m <- matrix(1:6, ncol = 3) tf <- tempfile() write(t(m), file = tf, ncolumns = 3) rm3 <- read_matrix(ncol = 3) rm3(tf)#> [,1] [,2] [,3] #> [1,] 1 3 5 #> [2,] 2 4 6