<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r-tip-think-in-terms-of-values/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2018/04/r-tip-think-in-terms-of-values/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://www.r-project.org/" target="_blank"><code>R</code></a> <a rel="nofollow" href="http://www.win-vector.com/blog/tag/r-tips/" target="_blank">tip</a>: first organize your tasks in terms of data, values, and desired transformation of values, not initially in terms of concrete functions or code.</p>
<p>I know I write <em>a lot</em> about coding in <code>R</code>. But it is in the service of supporting statistics, analysis, predictive analytics, and data science.</p>
<blockquote>
<p>
<code>R</code> without data is like going to the theater to watch the curtain go up and down. </p>
<p>
<center>
<p>(Adapted from Ben Katchor’s <em>Julius Knipl, Real Estate Photographer: Stories</em>, Little, Brown, and Company, 1996, page 72, “Excursionist Drama 2”.)<br>
</center>

</blockquote>
<p>Usually you come to <code>R</code> to work with data. If you think and plan in terms of data and values (including introducing more data to control processing) you will usually work in much faster, explainable, and maintainable fashion.</p>
<p><span></span></p>
<h2>A simple example</h2>
<p>Let’s start with a typical <a rel="nofollow" href="https://cran.r-project.org/package=dplyr" target="_blank"><code>dplyr</code></a> example. Suppose we wish to select two columns (in this case <code>c(&quot;name&quot;, &quot;height&quot;)</code>) from a <code>data.frame</code> (in this case <code>dplyr::starwars</code>). This is accomplished easily as we show below.</p>
<pre>
library(&quot;dplyr&quot;)

starwars %>%
  select(name, height)
# # A tibble: 87 x 2
#    name               height
#    </pre>