svmlight {sparsio} | R Documentation |
Reads and writes svmlight files. Notice that current implementation can't handle comments in svmlight files during reading.
read_svmlight(file, type = c("CsparseMatrix", "RsparseMatrix", "TsparseMatrix"), zero_based = TRUE, ncol = NULL) write_svmlight(x, y = rep(0, nrow(x)), file, zero_based = TRUE)
file |
string, path to svmlight file |
type |
target class for sparse matrix. |
zero_based |
|
ncol |
number of columns in target matrix. |
x |
input sparse matrix. Should inherit from |
y |
target values. Labels must be an integer or numeric of the same length as number of rows in |
library(Matrix) library(sparsio) i = 1:8 j = 1:8 v = rep(2, 8) x = sparseMatrix(i, j, x = v) y = sample(c(0, 1), nrow(x), replace = TRUE) f = tempfile(fileext = ".svmlight") write_svmlight(x, y, f) x2 = read_svmlight(f, type = "CsparseMatrix") identical(x2$x, x) identical(x2$y, y)