repmatch | R Documentation |
This pseudo-generic function iterates a function on the subelements of a list of objects that have the same class and matching dimensions/names and reorganizes the result to match the structure of the replicates or a prototype template.
repmatch(x, FUN = NULL, proto = NULL, direct = c("dim", "name"), ...)
x |
( |
FUN |
( |
proto |
( |
direct |
( |
... |
arguments passed to |
The function is designed to unify/merge objects that result from the same function applied to different source data (e.g. the results of subsample()
). In its current form, the function supports vectors
(including one-dimensional tables
and arrays
), matrix
and data.frame
objects.
If FUN
is a function
, the output is vector
for vector
-like replicates, matrix
when x
is a list
of matrix
objects, and data.frame
s for data.frame
replicates. In case FUN=NULL
: if x
is a list of vectors
, the function will return a matrix
; an array
is returned, if x
is a list
of matrix
class obejcts; if x
is a list of data.frame
objects, the function returns a data.frame
.
# basic example vect <- rnorm(100) # make 50 replicates repl <- rep(list(vect), 50) repmatch(repl, FUN=mean, direct="dim") # named input # two vectors # a a<- 1:10 names(a) <- letters[1:length(a)] a[c(3,5,8)] <- NA a <- a[!is.na(a)] #b b<- 10:1 names(b) <- letters[length(b):1] b[c(1, 3,6, length(b))]<- NA b <- b[!is.na(b)] # list x2 <- rep(c(list(a),list(b)), 3) # simple match - falling through "dim" to "name" directive repmatch(x2, FUN=NULL) # prototyped prot <- 1:10 names(prot) <-letters[1:10] repmatch(x2, FUN=mean, proto=prot, na.rm=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.