read.matrix.csr {e1071}R Documentation

read/write sparse data

Description

reads and writes a file in sparse data format.

Usage

read.matrix.csr(file, fac = TRUE, ncol = NULL)
write.matrix.csr(x, file = "out.dat", y = NULL)

Arguments

x An object of class matrix.csr
y A vector (either numeric or a factor)
file The filename.
fac If TRUE and y-values are stored in the file, the values are interpreted as factor levels.
ncol Number of columns, detected automatically. Can be used to add empty columns (these are not stored in the sparse format).

Value

If the data file includes no y variable, read.matrix.csr returns an object of class matrix.csr, else a list with components:

x object of class matrix.csr
y vector of numeric values or factor levels, depending on fac.

Author(s)

David Meyer (based on C/C++-code by Chih-Chung Chang and Chih-Jen Lin)
david.meyer@ci.tuwien.ac.at

See Also

matrix.csr

Examples

## Not run: 
  library(methods)
  if (require(SparseM)) {
    data(iris)
    x <- as.matrix(iris[,1:4])
    y <- iris[,5]
    xs <- as.matrix.csr(x)
    write.matrix.csr(xs, y = y, file="iris.dat")
    xs2 <- read.matrix.csr("iris.dat")$x
    if (!all(as.matrix(xs) == as.matrix(xs2)))
      stop("Error: objects are not equal!")
  }
## End(Not run)

[Package e1071 version 1.5-2 Index]