sparsetable objectsPackage idiom for creating and manipulating
sparsetable objects
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 sparsetable
index(x)
# S4 method for sparsetable
values(x)
# S4 method for sparsetable
dimnames(x)
# S4 method for sparsetable
dim(x)
In functions like index(), an object of class sparsetable
In standard constructor function sparsetable(),
argument i is the index matrix of strings, and v a
numeric vector of values
In functions rspar(), rspar2(), and
rsparr(), n is the number of terms, l the
number of letters, d the dimensionality and s the
number of distinct marginal values to return
Robin K. S. Hankin
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").
frab-class
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")
Run the code above in your browser using DataLab