Reads SVMLight sparse matrix file format. Requires Matrix
and sparsio
packages.
sparse.read(file, type = "CsparseMatrix", zero_based = TRUE, ncol = NULL)
file | Type: character. Path to your SVMLight file. |
---|---|
type | Type: character. The matrix output type, which can be |
zero_based | Type: logical. Whether columns are starting from |
ncol | Type: integer. The number of columns in the sparse matrix, useful in the case your data is very sparse and you already know the number of columns. |
The data from the SVMLight file.
library(Matrix) sparse_matrix <- sparseMatrix(i = 1:100, j = 1:100, x = 1:100) temp_file <- tempfile(fileext = ".svm") sparsio::write_svmlight(x = sparse_matrix, y = rep(1, ncol(sparse_matrix)), file = temp_file) sparse_matrix_read <- sparse.read(temp_file) identical(sparse_matrix, sparse_matrix_read$x)#> [1] TRUE