EVOLUTION-MANAGER
Edit File: colwise.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Column-wise function.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for colwise {plyr}"><tr><td>colwise {plyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Column-wise function.</h2> <h3>Description</h3> <p>Turn a function that operates on a vector into a function that operates column-wise on a data.frame. </p> <h3>Usage</h3> <pre> colwise(.fun, .cols = true, ...) catcolwise(.fun, ...) numcolwise(.fun, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.fun</code></td> <td> <p>function</p> </td></tr> <tr valign="top"><td><code>.cols</code></td> <td> <p>either a function that tests columns for inclusion, or a quoted object giving which columns to process</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>other arguments passed on to <code>.fun</code></p> </td></tr> </table> <h3>Details</h3> <p><code>catcolwise</code> and <code>numcolwise</code> provide version that only operate on discrete and numeric variables respectively. </p> <h3>Examples</h3> <pre> # Count number of missing values nmissing <- function(x) sum(is.na(x)) # Apply to every column in a data frame colwise(nmissing)(baseball) # This syntax looks a little different. It is shorthand for the # the following: f <- colwise(nmissing) f(baseball) # This is particularly useful in conjunction with d*ply ddply(baseball, .(year), colwise(nmissing)) # To operate only on specified columns, supply them as the second # argument. Many different forms are accepted. ddply(baseball, .(year), colwise(nmissing, .(sb, cs, so))) ddply(baseball, .(year), colwise(nmissing, c("sb", "cs", "so"))) ddply(baseball, .(year), colwise(nmissing, ~ sb + cs + so)) # Alternatively, you can specify a boolean function that determines # whether or not a column should be included ddply(baseball, .(year), colwise(nmissing, is.character)) ddply(baseball, .(year), colwise(nmissing, is.numeric)) ddply(baseball, .(year), colwise(nmissing, is.discrete)) # These last two cases are particularly common, so some shortcuts are # provided: ddply(baseball, .(year), numcolwise(nmissing)) ddply(baseball, .(year), catcolwise(nmissing)) # You can supply additional arguments to either colwise, or the function # it generates: numcolwise(mean)(baseball, na.rm = TRUE) numcolwise(mean, na.rm = TRUE)(baseball) </pre> <hr /><div style="text-align: center;">[Package <em>plyr</em> version 1.8.7 <a href="00Index.html">Index</a>]</div> </body></html>