sparsetable {frab} | R Documentation |
Generalized sparse tables: sparsetable
objects
Description
Package idiom for creating and manipulating
sparsetable
objects
Usage
sparsetable(i,v=1)
rspar(n=15,l=3,d=3)
rspar2(n=15,l=6)
rsparr(n=20,d=6,l=5,s=4)
sparsetable_to_array(x)
array_to_sparsetable(x)
sparsetable_to_frab(x)
## S4 method for signature 'sparsetable'
index(x)
## S4 method for signature 'sparsetable'
values(x)
## S4 method for signature 'sparsetable'
dimnames(x)
## S4 method for signature 'sparsetable'
dim(x)
Arguments
x |
In functions like |
i , v |
In standard constructor function |
n , l , d , s |
In functions |
Details
Most functions here mirror their equivalent in the spray
package [which the C code is largely copied from] or the
frab
functionality. So, for example, num_eq_sparsetable()
is the equivalent of num_eq_spray()
.
The print method treats arity-2 sparsetable
objects differently
from other arities. By default, arity-2 sparsetable
objects are
displayed as two-dimensional tables. Control this behaviour with option
print_2dsparsetables_as_matrices
:
options("print_2dsparsetables_as_matrices" = FALSE)
The default value for this option, non-FALSE
(including its
out-of-the-box status of “unset”), directs the print method to
coerce arity-2 sparsetable
objects to two-dimensional tables
before printing. If this option is FALSE
, arity-2 sparsetables
are printed using matrix index form, just the same as any other arity.
Functions rspar()
, rspar2()
, and rsparr()
create
random sparsetable
objects of increasing complexity. The
defaults are chosen so that the returned frabs are of sensible sizes.
Function drop()
takes a sparsetable object of arity one and
coerces to a frab
object.
Function dim()
returns a named vector, with names being the
dimnames
of its argument.
Extraction and replacement methods are a subset of spray
methods, but most should work. There is special dispensation so that
standard idiom for arrays [e.g. x['a','b','a']
and
x['a','b','a'] <- 55
] should work as expected, although the
general expectation is that access and replacement use (character)
matrices and an index object. However, indexing by disord
and
disindex
objects should also work [e.g. x[x>7]
].
The spray source code and the sparsetable
functionality
have about 90% overlap; there were enough small differences between the
codes to make it worth maintaining two sets of source code, IMO.
There is a discussion of package idiom in the vignette,
vignette("frab")
.
Note
The pronunciation of “sparsetable” has the emphasis on the first syllable, so it rhymes with [British river-port town] “Barnstaple”.
Author(s)
Robin K. S. Hankin
See Also
Examples
sparsetable(matrix(sample(letters[1:4],36,replace=TRUE),ncol=2),1:18)
sparsetable(matrix(sample(letters[1:4],39,replace=TRUE),ncol=3),1:13)
(x <- rspar2(9))
(y <- rspar2(9))
x + y
x["KT","FF"] <- 100
x
rsparr()
a <- rspar(d=4)
asum(a,"Feb")