Learn R Programming

sparta (version 1.0.1)

as_sparta: As sparse table

Description

Turn an array-like object or a data.frame into a sparse representation

Usage

as_sparta(x)

# S3 method for array as_sparta(x)

# S3 method for matrix as_sparta(x)

# S3 method for table as_sparta(x)

# S3 method for sparta as_sparta(x)

# S3 method for data.frame as_sparta(x)

Value

A sparta object

Arguments

x

array-like object or a data.frame

References

<doi:10.18637/jss.v111.i02>

See Also

as_array

Examples

Run this code

# ----------
# Example 1)
# ----------

x <- array(
  c(1,0,0,2,3,4,0,0),
  dim = c(2,2,2),
  dimnames = list(
    a = c("a1", "a2"),
    b = c("b1", "b2"),
    c = c("c1", "c2")
  )
)

as_sparta(x)

# ----------
# Example 2)
# ----------

y   <- mtcars[, c("gear", "carb")]
y[] <- lapply(y, as.character)
as_sparta(y)

Run the code above in your browser using DataLab