Returns a list containing the indices and elements of a spam object.

triplet(x, tri=FALSE)

Arguments

x

sparse matrix of class spam or a matrix.

tri

Boolean indicating whether to create individual row and column indices vectors.

Value

A list with elements

indices

a by two matrix containing the indices if tri=FALSE.

i,j

vectors containing the row and column indices if tri=TRUE.

values

a vector containing the matrix elements.

Details

The elements are row (column) first if x is a spam object (matrix).

See also

spam.creation for the inverse operation and foreign for other transformations.

Author

Reinhard Furrer

Examples

x <- diag.spam(1:4)
x[2,3] <- 5
triplet(x)
#> $indices
#>      [,1] [,2]
#> [1,]    1    1
#> [2,]    2    2
#> [3,]    2    3
#> [4,]    3    3
#> [5,]    4    4
#> 
#> $values
#> [1] 1 2 5 3 4
#> 
all.equal( spam( triplet(x, tri=TRUE)), x)
#> [1] TRUE