Description Usage Arguments Details Value See Also Examples
View source: R/summaryFunction.R
Convert a function, f
, into an S3
summaryFunction
object. This adds f
to the
overview list returned by an allSummaryFunctions()
call.
1 | summaryFunction(f, description, classes = NULL)
|
f |
A function. See details and examples below for the exact requirements of this function. |
description |
A character string describing the summary
returned by |
classes |
The classes for which |
summaryFunction
represents the functions used in
summarize
and makeDataReport
for summarizing the
features of variables in a dataset.
An example of defining a new summaryFunction
is given below.
Note that the minimal requirements for such a function (in order for it to be
compatible with summarize()
and makeDataReport()
) is the following
input/output-structure: It must input at least two arguments, namely
v
(a vector variable) and ...
. Additional implemented
arguments from summarize()
and makeDataReport()
include
maxDecimals
, see e.g. the pre-defined summaryFunction
minMax
for more details about how this arguments should
be used.
The output must be a list with at least the two entries $feature
(a short character string describing what was summarized) and $result
(a value or a character string with the result of the summarization).
However, if the result of a summaryFunction
is furthermore
converted to a summaryResult
object, a print()
method also becomes available for consistent formatting of
summaryFunction
results.
Note that all available summaryFunction
s are listed by the call
allSummaryFunctions()
and we recommed looking into these function,
if more knowledge about summaryFunction
s is required.
A function of class summaryFunction
which has to attributes,
namely classes
and description
.
allSummaryFunctions
, summarize
,
makeDataReport
, checkResult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #Define a valid summaryFunction that can be called from summarize()
#and makeDataReport(). This function counts how many zero entries a given
#variable has:
countZeros <- function(v, ...) {
res <- length(which(v == 0))
summaryResult(list(feature = "No. zeros", result = res, value = res))
}
#Convert it to a summaryFunction object. We don't count zeros for
#logical variables, as they have a different meaning here (FALSE):
countZeros <- summaryFunction(countZeros, description = "Count number of zeros",
classes = setdiff(allClasses(), "logical"))
#Call it directly :
countZeros(c(0, 0, 0, 1:100))
#Call it via summarize():
data(cars)
summarize(cars, numericSummaries = c(defaultNumericSummaries(),
"countZeros"))
#Note that countZeros now appears in a allSummaryFunctions() call:
allSummaryFunctions()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.