Writes SVMLight sparse matrix file format. Requires Matrix
and sparsio
packages.
sparse.write(file, x, y = numeric(nrow(x)), zero_based = TRUE)
file | Type: character. Path to your SVMLight file. |
---|---|
x | Type: any supported sparse matrix. The sparse matrix to write as SVMLight file format. Defaults to |
y | Type: integer vector. The labels associated to the corresponding rows. |
zero_based | Type: logical. Whether columns are starting from |
TRUE when the function returns.
library(Matrix) sparse_matrix <- sparseMatrix(i = 1:100, j = 1:100, x = 1:100) temp_file <- tempfile(fileext = ".svm") sparse.write(file = temp_file, x = sparse_matrix, y = rep(1, ncol(sparse_matrix))) sparse_matrix_read <- sparsio::read_svmlight(temp_file) identical(sparse_matrix, sparse_matrix_read$x)#> [1] TRUE