EVOLUTION-MANAGER
Edit File: asplit.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: Split Array/Matrix By Its Margins</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 asplit {base}"><tr><td>asplit {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Split Array/Matrix By Its Margins</h2> <h3>Description</h3> <p>Split an array or matrix by its margins.</p> <h3>Usage</h3> <pre> asplit(x, MARGIN) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an array, including a matrix.</p> </td></tr> <tr valign="top"><td><code>MARGIN</code></td> <td> <p>a vector giving the margins to split by. E.g., for a matrix <code>1</code> indicates rows, <code>2</code> indicates columns, <code>c(1, 2)</code> indicates rows and columns. Where <code>x</code> has named dimnames, it can be a character vector selecting dimension names.</p> </td></tr> </table> <h3>Details</h3> <p>The values of the splits can also be obtained (less efficiently) by <code>split(x, slice.index(x, MARGIN))</code>. </p> <p><code><a href="apply.html">apply</a></code> always simplifies common length results, so attempting to split via <code>apply(x, MARGIN, identity)</code> does not work (as it simply gives <code>x</code>). By chaining <code>asplit</code> with <code><a href="lapply.html">lapply</a></code> or <code><a href="lapply.html">vapply</a></code>, one can obtain variants of <code>apply</code> which do not auto-simplify. </p> <h3>Value</h3> <p>A “list array” with dimension <i>dv</i> and each element an array of dimension <i>de</i> and dimnames preserved as available, where <i>dv</i> and <i>de</i> are, respectively, the dimensions of <code>x</code> included and not included in <code>MARGIN</code>. </p> <h3>Examples</h3> <pre> ## A 3-dimensional array of dimension 2 x 3 x 4: d <- 2 : 4 x <- array(seq_len(prod(d)), d) x ## Splitting by margin 2 gives a 1-d list array of length 3 ## consisting of 2 x 4 arrays: asplit(x, 2) ## Spltting by margins 1 and 2 gives a 2 x 3 list array ## consisting of 1-d arrays of length 4:a asplit(x, c(1, 2)) ## Compare to split(x, slice.index(x, c(1, 2))) ## A 2 x 3 matrix: (x <- matrix(1 : 6, 2, 3)) ## To split x by its rows, one can use asplit(x, 1) ## or less efficiently split(x, slice.index(x, 1)) split(x, row(x)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>