<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/data-transformation-in-tidyverse-style-package-sjmisc-updated-rstats/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://strengejacke.wordpress.com/2018/02/06/data-transformation-in-tidyverse-style-package-sjmisc-updated-rstats/"> R – Strenge Jacke!</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’m pleased to announce an update for the <a rel="nofollow" href="https://cran.r-project.org/package=sjmisc" target="_blank">sjmisc-package</a>, which was just released on CRAN. Here I want to point out two important changes in the package.</p>
<h2>New default option for recoding and transformation functions</h2>
<p>First, a small change in the code with major impact on the workflow, as it affects argument defaults and is likely to break your existing code – if you’re using <em>sjmisc</em>: The <code>append</code>-argument in recode and transformation functions like <code>rec()</code>, <code>dicho()</code>, <code>split_var()</code>, <code>group_var()</code>, <code>center()</code>, <code>std()</code>, <code>recode_to()</code>, <code>row_sums()</code>, <code>row_count()</code>, <code>col_count()</code> and <code>row_means()</code> now defaults to <code>TRUE</code>.</p>
<p>The reason behind this change is that, in my experience and workflow, when transforming or recoding variables, I typically want to add these new variables to an existing data frame <em>by default</em>. Especially in a pipe-workflow, when I start my scripts with importing and basic tidying of my data, I almost always want to append the recoded variables to my existing data, e.g.:</p>
<pre><code><span># Example with following steps:
# 1. loading labelled data set
# 2. dropping unused labels
# 3. converting numeric into categorical, using labels as levels
# 4. center some variables
# 5. recode some other variables</span>
data %>%
  drop_labels() %>%
  as_label(var1:var5) %>%
  center(var7, var9) %>%
  rec(var11, rec = &quot;2=0;1=1;else=copy&quot;)</code></pre>
<p><span></span></p>
<p>The above code would return a data frame with 3 <em>new, additional</em> variables, <em>var7_c</em> and <em>var9_c</em> (centered) and <em>var11_r</em> (recoded).</p>
<p>In the past package versions, the <code>append</code>-argument defaulted to <code>FALSE</code>, which means that functions like <code>rec()</code> or <code>center()</code> <em>did not</em> return the input data frame <em>including</em> the new variables, but <em>only</em> the new, transformed variables. This was a behaviour that turned out to be less practical as default option.</p>
<h2>Freak out</h2>
<p>The second change is a revision of the <code>frq()</code> function, which prints frequency tables in a clean and well-arranged way to console (or as HTML table). <code>frq()</code> now prints more summary statistics in the headline, as well as the variable name and type:</p>
<pre><code>library(tidyverse)
library(strengejacke)
<span># Get pkg &quot;strengejacke&quot; from Github:
# https://github.com/strengejacke/strengejacke
# it simply loads 4 of my packages at once...</span>

data(efc)
frq(efc, e42dep, e15relat)

<span>#></span> <span># elder's dependency (e42dep) </span></code></pre>