Description Usage Arguments Value See Also Examples
The apply
function in S-PLUS is S3 generic,
but it is not so in R. For the msProcess package, the apply
function is overloaded to be an S3 generic function, relying on
UseMethod("apply")
to distribute the call. The apply.default
function is defined to be base::apply
, so if the class of
the X
input is not "msSet"
then the standard R definition will
be used.
1 |
X |
an |
MARGIN |
an integer denoting the dimension over which the
given function is applied. Use |
FUN |
a function to be applied to the specified array sections, or a character string giving the name of the function. |
... |
any arguments to |
type |
a character string specifying the name of the array in the |
pre |
a function that is applied to the matrix prior to
processing the data. Typical examples would be |
covar |
a named list of additional matrices to be parsed in the
same manner as the primary matrix (specified by
will ultimately result in calls
|
a matrix containing the result of the FUN
function applied to the matrix
of type type
found in the original msSet object X
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | if (!exists("qcset")) data("qcset", package="msProcess")
# find the means of each spectrum
# and convert the result to a single-row matrix
means <- apply(qcset, MARGIN=2, mean)
nc <- NCOL(qcset$intensity)
means <- matrix(means, ncol=nc)
print(means)
# add the means (single-row) matrix to the original
# msSet object and verify its existence
z <- msSet(qcset, means=means)
names(z)
is.matrix(z$means)
# to illustrate the use of the 'covar' argument in apply,
# create a faux function that finds tha maximum absolute
# difference between each spectrum and its mean value
foo <- function(x,meanvals) max(abs(x-meanvals))
maxdiff <- as.vector(apply(z, MARGIN=2, FUN=foo, covar=list(meanvals=means)))
print(maxdiff)
# verify the results: should get vector of nc zeros
unlist(lapply(seq(along=maxdiff), function(i,z,maxdiff)
vecnorm(max(abs(z$intensity[,i]-z$means[,i])) - maxdiff[i]),
z=z, maxdiff=maxdiff))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.