sparse.write: SVMLight file writer

Description Usage Arguments Value Examples

View source: R/sparse.write.R

Description

Writes SVMLight sparse matrix file format. Requires Matrix and sparsio packages.

Usage

1
sparse.write(file, x, y = numeric(nrow(x)), zero_based = TRUE)

Arguments

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 numeric(nrow(x)).

y

Type: integer vector. The labels associated to the corresponding rows.

zero_based

Type: logical. Whether columns are starting from 0 (TRUE), or from 1 (FALSE). Defaults to TRUE.

Value

TRUE when the function returns.

Examples

1
2
3
4
5
6
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)

Laurae2/LauraeDS documentation built on May 29, 2019, 2:25 p.m.