Description Usage Arguments Value Author(s) See Also Examples
reads and writes a file in sparse data format.
1 2 | read.matrix.csr(file, fac = TRUE, ncol = NULL)
write.matrix.csr(x, file = "out.dat", y = NULL, fac = TRUE)
|
x |
An object of class |
y |
A vector (either numeric or a factor) |
file |
The filename. |
fac |
If |
ncol |
Number of columns, detected automatically. Can be used to add empty columns (possibly not stored in the sparse format). |
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 |
y |
vector of numeric values or factor levels, depending on |
David Meyer
David.Meyer@R-project.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.