EVOLUTION-MANAGER
Edit File: mapvalues.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: Replace specified values with new values, in a vector or...</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 mapvalues {plyr}"><tr><td>mapvalues {plyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Replace specified values with new values, in a vector or factor.</h2> <h3>Description</h3> <p>Item in <code>x</code> that match items <code>from</code> will be replaced by items in <code>to</code>, matched by position. For example, items in <code>x</code> that match the first element in <code>from</code> will be replaced by the first element of <code>to</code>. </p> <h3>Usage</h3> <pre> mapvalues(x, from, to, warn_missing = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>the factor or vector to modify</p> </td></tr> <tr valign="top"><td><code>from</code></td> <td> <p>a vector of the items to replace</p> </td></tr> <tr valign="top"><td><code>to</code></td> <td> <p>a vector of replacement values</p> </td></tr> <tr valign="top"><td><code>warn_missing</code></td> <td> <p>print a message if any of the old values are not actually present in <code>x</code></p> </td></tr> </table> <h3>Details</h3> <p>If <code>x</code> is a factor, the matching levels of the factor will be replaced with the new values. </p> <p>The related <code>revalue</code> function works only on character vectors and factors, but this function works on vectors of any type and factors. </p> <h3>See Also</h3> <p><code><a href="revalue.html">revalue</a></code> to do the same thing but with a single named vector instead of two separate vectors. </p> <h3>Examples</h3> <pre> x <- c("a", "b", "c") mapvalues(x, c("a", "c"), c("A", "C")) # Works on factors y <- factor(c("a", "b", "c", "a")) mapvalues(y, c("a", "c"), c("A", "C")) # Works on numeric vectors z <- c(1, 4, 5, 9) mapvalues(z, from = c(1, 5, 9), to = c(10, 50, 90)) </pre> <hr /><div style="text-align: center;">[Package <em>plyr</em> version 1.8.7 <a href="00Index.html">Index</a>]</div> </body></html>