Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Jun 23, 2024
1 parent c29173c commit 9ded6d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions _posts/2024-06-09-ave-for-the-average/ave-for-the-average.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ It's the perfect mashup of base R + tidyverse. Base R takes care of the problem

tidyverse 🤝 base R

## Aside: data.table 🤝 collapse
## Aside: `{data.table}` 🤝 `{collapse}`

Since I wrote this blog post, I discovered that `{data.table}` recently added in support for using `names(.SD)` in the LHS of the walrus `:=`. I'm so excited for this to hit the next release (v1.6.0)!
Since I wrote this blog post, I discovered that `{data.table}` recently added in support for using `names(.SD)` in the LHS of the walrus `:=`. I'm so excited for this to hit the [next release](https://rdatatable.gitlab.io/data.table/news/index.html) (v1.16.0)!

I've trying to be more mindful of showcasing `{data.table}` whenever I talk about `{dplyr}`, so here's a solution to compare with the `dplyr::across()` solution above.

Expand Down Expand Up @@ -209,7 +209,7 @@ ave(input_dt$freq, input_dt$a, FUN = sum)
fsum(input_dt$freq, input_dt$a, TRA = "replace") # Also, TRA = 2
```

So the version of the solution integrating `fsum()` would be:^[I couldn't show this here with this particular example, but another nice feature of `{collapse}` 🤝 `{data.table}` is the fact that they do not shy away from consuming/producing matrices: see `scale()[,1]` vs. `fscale()` for a good example of this.]
So a version of the solution integrating `fsum()` would be:^[I couldn't show this here with this particular example, but another nice feature of `{collapse}` 🤝 `{data.table}` is the fact that they do not shy away from consuming/producing matrices: see `scale()[,1]` vs. `fscale()` for a good example of this.]

```{r}
input_dt[, names(.SD) := NULL, .SDcols = patterns("^freq_")]
Expand Down
10 changes: 5 additions & 5 deletions _posts/2024-06-09-ave-for-the-average/ave-for-the-average.html
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ <h3>Contents</h3>
<li><a href="#the-problem" id="toc-the-problem">The problem</a></li>
<li><a href="#some-tidyverse-solutions" id="toc-some-tidyverse-solutions">Some <code>{tidyverse}</code> solutions</a></li>
<li><a href="#an-ave-dplyr-solution" id="toc-an-ave-dplyr-solution">An <code>ave()</code> + <code>{dplyr}</code> solution</a></li>
<li><a href="#aside-data.table-collapse" id="toc-aside-data.table-collapse">Aside: data.table 🤝 collapse</a></li>
<li><a href="#aside-data.table-collapse" id="toc-aside-data.table-collapse">Aside: <code>{data.table}</code> 🤝 <code>{collapse}</code></a></li>
<li><a href="#sessioninfo" id="toc-sessioninfo">sessionInfo()</a></li>
</ul>
</nav>
Expand All @@ -1585,7 +1585,7 @@ <h2 id="ave"><code>ave()</code></h2>
}
x
}
&lt;bytecode: 0x000002dc894a8f80&gt;
&lt;bytecode: 0x0000029931326f80&gt;
&lt;environment: namespace:stats&gt;</code></pre>
</div>
<p>Despite its (rather generic and uninformative) name, I like to think of <code>ave()</code> as actually belonging to the <code>*apply()</code> family of functions, having particularly close ties to <code>tapply()</code>.</p>
Expand Down Expand Up @@ -1762,8 +1762,8 @@ <h2 id="an-ave-dplyr-solution">An <code>ave()</code> + <code>{dplyr}</code> solu
<p>From there, <code>across()</code> handles the iteration over columns and, as an added bonus, the naming of the new columns in convenient <code>{glue}</code> syntax (<code>"freq_{.col}"</code>).</p>
<p>It’s the perfect mashup of base R + tidyverse. Base R takes care of the problem at the vector level with a split-apply-combine that’s concisely expressed with <code>ave()</code>, and tidyverse scales that solution up to the dataframe level with <code>mutate()</code> and <code>across()</code>.</p>
<p>tidyverse 🤝 base R</p>
<h2 id="aside-data.table-collapse">Aside: data.table 🤝 collapse</h2>
<p>Since I wrote this blog post, I discovered that <code>{data.table}</code> recently added in support for using <code>names(.SD)</code> in the LHS of the walrus <code>:=</code>. I’m so excited for this to hit the next release (v1.6.0)!</p>
<h2 id="aside-data.table-collapse">Aside: <code>{data.table}</code> 🤝 <code>{collapse}</code></h2>
<p>Since I wrote this blog post, I discovered that <code>{data.table}</code> recently added in support for using <code>names(.SD)</code> in the LHS of the walrus <code>:=</code>. I’m so excited for this to hit the <a href="https://rdatatable.gitlab.io/data.table/news/index.html">next release</a> (v1.16.0)!</p>
<p>I’ve trying to be more mindful of showcasing <code>{data.table}</code> whenever I talk about <code>{dplyr}</code>, so here’s a solution to compare with the <code>dplyr::across()</code> solution above.</p>
<div class="layout-chunk" data-layout="l-body">

Expand Down Expand Up @@ -1806,7 +1806,7 @@ <h2 id="aside-data.table-collapse">Aside: data.table 🤝 collapse</h2>
</div>
<pre><code> [1] 20 20 20 7</code></pre>
</div>
<p>So the version of the solution integrating <code>fsum()</code> would be:<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
<p>So a version of the solution integrating <code>fsum()</code> would be:<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>input_dt</span><span class='op'>[</span>, <span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>.SD</span><span class='op'>)</span> <span class='op'>:=</span> <span class='cn'>NULL</span>, .SDcols <span class='op'>=</span> <span class='fu'>patterns</span><span class='op'>(</span><span class='st'>"^freq_"</span><span class='op'>)</span><span class='op'>]</span></span>
Expand Down
10 changes: 5 additions & 5 deletions docs/posts/2024-06-09-ave-for-the-average/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ <h3>Contents</h3>
<li><a href="#the-problem" id="toc-the-problem">The problem</a></li>
<li><a href="#some-tidyverse-solutions" id="toc-some-tidyverse-solutions">Some <code>{tidyverse}</code> solutions</a></li>
<li><a href="#an-ave-dplyr-solution" id="toc-an-ave-dplyr-solution">An <code>ave()</code> + <code>{dplyr}</code> solution</a></li>
<li><a href="#aside-data.table-collapse" id="toc-aside-data.table-collapse">Aside: data.table 🤝 collapse</a></li>
<li><a href="#aside-data.table-collapse" id="toc-aside-data.table-collapse">Aside: <code>{data.table}</code> 🤝 <code>{collapse}</code></a></li>
<li><a href="#sessioninfo" id="toc-sessioninfo">sessionInfo()</a></li>
</ul>
</nav>
Expand All @@ -2719,7 +2719,7 @@ <h2 id="ave"><code>ave()</code></h2>
}
x
}
&lt;bytecode: 0x000002dc894a8f80&gt;
&lt;bytecode: 0x0000029931326f80&gt;
&lt;environment: namespace:stats&gt;</code></pre>
</div>
<p>Despite its (rather generic and uninformative) name, I like to think of <code>ave()</code> as actually belonging to the <code>*apply()</code> family of functions, having particularly close ties to <code>tapply()</code>.</p>
Expand Down Expand Up @@ -2896,8 +2896,8 @@ <h2 id="an-ave-dplyr-solution">An <code>ave()</code> + <code>{dplyr}</code> solu
<p>From there, <code>across()</code> handles the iteration over columns and, as an added bonus, the naming of the new columns in convenient <code>{glue}</code> syntax (<code>"freq_{.col}"</code>).</p>
<p>It’s the perfect mashup of base R + tidyverse. Base R takes care of the problem at the vector level with a split-apply-combine that’s concisely expressed with <code>ave()</code>, and tidyverse scales that solution up to the dataframe level with <code>mutate()</code> and <code>across()</code>.</p>
<p>tidyverse 🤝 base R</p>
<h2 id="aside-data.table-collapse">Aside: data.table 🤝 collapse</h2>
<p>Since I wrote this blog post, I discovered that <code>{data.table}</code> recently added in support for using <code>names(.SD)</code> in the LHS of the walrus <code>:=</code>. I’m so excited for this to hit the next release (v1.6.0)!</p>
<h2 id="aside-data.table-collapse">Aside: <code>{data.table}</code> 🤝 <code>{collapse}</code></h2>
<p>Since I wrote this blog post, I discovered that <code>{data.table}</code> recently added in support for using <code>names(.SD)</code> in the LHS of the walrus <code>:=</code>. I’m so excited for this to hit the <a href="https://rdatatable.gitlab.io/data.table/news/index.html">next release</a> (v1.16.0)!</p>
<p>I’ve trying to be more mindful of showcasing <code>{data.table}</code> whenever I talk about <code>{dplyr}</code>, so here’s a solution to compare with the <code>dplyr::across()</code> solution above.</p>
<div class="layout-chunk" data-layout="l-body">

Expand Down Expand Up @@ -2940,7 +2940,7 @@ <h2 id="aside-data.table-collapse">Aside: data.table 🤝 collapse</h2>
</div>
<pre><code> [1] 20 20 20 7</code></pre>
</div>
<p>So the version of the solution integrating <code>fsum()</code> would be:<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
<p>So a version of the solution integrating <code>fsum()</code> would be:<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>input_dt</span><span class='op'>[</span>, <span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>.SD</span><span class='op'>)</span> <span class='op'>:=</span> <span class='cn'>NULL</span>, .SDcols <span class='op'>=</span> <span class='fu'>patterns</span><span class='op'>(</span><span class='st'>"^freq_"</span><span class='op'>)</span><span class='op'>]</span></span>
Expand Down
Loading

0 comments on commit 9ded6d8

Please sign in to comment.