sparse.read: SVMLight file reader

Description Usage Arguments Value Examples

View source: R/sparse.read.R

Description

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

Usage

1
sparse.read(file, type = "CsparseMatrix", zero_based = TRUE, ncol = NULL)

Arguments

file

Type: character. Path to your SVMLight file.

type

Type: character. The matrix output type, which can be CsparseMatrix, RsparseMatrix, TsparseMatrix. Defaults to CsparseMatrix.

zero_based

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

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.

Value

The data from the SVMLight file.

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")
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)

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