Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mipply

Apply a Function to a Object of Class mi


Description

This function is a wrapper around sapply that is invoked on the data slot of an object of mi-class and / or on an object of missing_data.frame-class after being coerced to a data.frame

Usage

mipply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE, 
       columnwise = TRUE, to.matrix = FALSE)

Arguments

X

Object of mi-class, missing_data.frame-class, missing_variable-class, mi_list-class, or mdf_list-class

FUN

Function to call

...

Further arguments passed to FUN, currently broken

simplify

If TRUE, coerces result to a vector or matrix if possible

USE.NAMES

ignored but included for compatibility with sapply

columnwise

logical indicating whether to invoke FUN on the columns of a missing_data.frame after coercing it to a data.frame or a matrix or to invoke FUN on the “whole” data.frame or matrix

to.matrix

Logical indicating whether to coerce each missing_data.frame to a numeric matrix or to a data.frame. The default is FALSE, in which case the data.frame will include factors if any of the missing_variables inherit from categorical-class

Details

The columnwise and to.matrix arguments are the only additions to the argument list in sapply, see the Examples section for an illustration of their use. Note that functions such as mean only accept numeric inputs, which can produce errors or warnings when to.matrix = FALSE.

Value

A list, vector, or matrix depending on the arguments

Author(s)

Ben Goodrich and Jonathan Kropko, for this version, based on earlier versions written by Yu-Sung Su, Masanao Yajima, Maria Grazia Pittau, Jennifer Hill, and Andrew Gelman.

See Also

Examples

if(!exists("imputations", env = .GlobalEnv)) {
  imputations <- mi:::imputations # cached from example("mi-package")
}
round(mipply(imputations, mean, to.matrix = TRUE), 3)
mipply(imputations, summary, columnwise = FALSE)

mi

Missing Data Imputation and Model Checking

v1.0
GPL (>= 2)
Authors
Andrew Gelman [ctb], Jennifer Hill [ctb], Yu-Sung Su [aut], Masanao Yajima [ctb], Maria Pittau [ctb], Ben Goodrich [cre, aut], Yajuan Si [ctb], Jon Kropko [aut]
Initial release
2015-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.