| grid-stuff | R Documentation |
From a variable specification list (varlist),
gets elements of a variable specification
list that match the given variable type.
builds a grid, e.g., for parallel evaluation,
basically by calling do.call(expand.grid, <list>).
builds a list
of names, e.g., to be used as dimnames for a
corresponding simulation result array.
extracts n.sim or returns 1 if it
is not contained in vList.
modifies or sets n.sim in vList.
extracts all variables not having
type="grid" and returns n.sim the same as
get.n.sim().
getEl (vList, type = "ALL", comp = "value")
mkGrid (vList)
mkNms (vList, addNms = FALSE)
get.n.sim (vList)
set.n.sim (vList, n)
get.nonGrids(vList)
vList |
a |
type |
|
comp |
either a |
addNms |
logical, specifying if the resulting names should be of
the form |
n |
for |
These functions are useful when working with variable specification lists.
For
a named list containing the selected
components of those variables that match the provided type.
a data frame (data.frame).
a named list of the same
length() and with the same names() as
vList.
n.sim if it is contained in vList,
1 otherwise.
the varlist vList with a
modified n.sim.
list of length 2 containing the
(possibly modified) n.sim and a list
containing all variables not having type="grid".
Marius Hofert and Martin Maechler.
varlist, for construction of variable lists.
expand.grid, the “workhorse” of mkGrid().
vList <-
varlist(n.sim = list(type="N", expr = quote(N[sim]), value = 64),
n = list(type="grid",
value = c(20, 100, 500)), # sample sizes
p = list(type="grid",
value = c(3, 7, 15, 25)), # dimensions
meth = list(type="grid", expr = quote(italic(method)),
value = c("classical", "robust")))
getEl(vList, type="grid") # for those of type "grid", get all values
## for those of type "grid", get all components :
str(getEl(vList, type="grid", comp=NA))
stopifnot(identical(as(vList, "list"),
getEl(vList, type=c("N","grid"), comp = NA)))
(grd <- mkGrid(vList))
stopifnot(nrow(grd) == 3*4*2, ncol(grd) == 3)
getEl(vList)# -> all "value"s: the same as lapply(., `[[`, "value") :
stopifnot(identical(lapply(vList, `[[`, "value"),
getEl(vList)))
mkNms(vList)
mkNms(vList, addNms=TRUE)
get.n.sim(vl. <- set.n.sim(vList, NULL)) # 1
vl.$n.sim # NULL
set.n.sim(vl., 12)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.