EVOLUTION-MANAGER
Edit File: nth.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: Extract the first, last or nth value from a vector</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 nth {dplyr}"><tr><td>nth {dplyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract the first, last or nth value from a vector</h2> <h3>Description</h3> <p>These are straightforward wrappers around <code><a href="../../base/html/Extract.html">[[</a></code>. The main advantage is that you can provide an optional secondary vector that defines the ordering, and provide a default value to use when the input is shorter than expected. </p> <h3>Usage</h3> <pre> nth(x, n, order_by = NULL, default = default_missing(x)) first(x, order_by = NULL, default = default_missing(x)) last(x, order_by = NULL, default = default_missing(x)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A vector</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>For <code>nth_value()</code>, a single integer specifying the position. Negative integers index from the end (i.e. <code>-1L</code> will return the last value in the vector). </p> <p>If a double is supplied, it will be silently truncated.</p> </td></tr> <tr valign="top"><td><code>order_by</code></td> <td> <p>An optional vector used to determine the order</p> </td></tr> <tr valign="top"><td><code>default</code></td> <td> <p>A default value to use if the position does not exist in the input. This is guessed by default for base vectors, where a missing value of the appropriate type is returned, and for lists, where a <code>NULL</code> is return. </p> <p>For more complicated objects, you'll need to supply this value. Make sure it is the same type as <code>x</code>.</p> </td></tr> </table> <h3>Value</h3> <p>A single value. <code>[[</code> is used to do the subsetting. </p> <h3>Examples</h3> <pre> x <- 1:10 y <- 10:1 first(x) last(y) nth(x, 1) nth(x, 5) nth(x, -2) nth(x, 11) last(x) # Second argument provides optional ordering last(x, y) # These functions always return a single value first(integer()) </pre> <hr /><div style="text-align: center;">[Package <em>dplyr</em> version 1.0.2 <a href="00Index.html">Index</a>]</div> </body></html>