<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/r-questions-tag-pairs-on-stackoverflow/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://omaymas.github.io/R_Q_Tags/"> Once Upon Data</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Months ago, I passed by <a target="_blank" rel="nofollow" href="https://www.kaggle.com/stackoverflow/rquestions">R Questions from Stack Overflow</a> published on <a target="_blank" rel="nofollow" href="https://www.kaggle.com/datasets">Kaggle</a>. I was interested in tag pairs in particular, <em>i.e. which tags appear together in R questions</em>, so I worked on this simple <a target="_blank" rel="nofollow" href="https://www.kaggle.com/omaymas/tag-pairs-frequency-r-questions">kernel</a>.</p>
<p>This week, I had some time so I thought about deploying a simple <a target="_blank" rel="nofollow" href="https://omaymas.shinyapps.io/r-tags/">Shiny App</a>, to give more people access to exploring the tag pairs. So here is the App, where you can see the most frequent tags that appear with a certain tag. And below is the full code of how I processed and aggregated the data.</p>
<h2>R Tag Pairs Shiny App</h2>
<p><center><br>
<iframe src="https://omaymas.shinyapps.io/r-tags/"></iframe><br>
</center></p>
<h2>Data Aggregation</h2>
<p>I selected the questions with <strong>more than one tag</strong> <em>(in addition to R)</em> and did the following:</p>
<ul>
<li><strong>Step 1</strong>: get all the tags corresponding to question ID</li>
<li><strong>Step 2</strong>: find all pair combinations from these tags</li>
<li><strong>Step 3</strong>: combine all pairs from all the questions in one dataframe</li>
</ul>
<h3>Step 1: get all the tags corresponding to question ID</h3>
<div>
<pre><code><span># group by question ID and nest tags
</span><span>datn</span><span> </span><span>&lt;-</span><span> </span><span>dat</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Id</span><span>)</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>n</span><span>()</span><span>></span><span>1</span><span>)</span><span> </span><span>%>%</span><span> </span><span>nest</span><span>(</span><span>.key</span><span>=</span><span>&quot;Tags&quot;</span><span>)</span><span>
</span></code></pre>
</div>
<p>Now if we look at a certain question ID, we find all the tags in one list, for example for Q#79709</p>
<div>
<pre><code>[[1]]
# A tibble: 4 × 1
               Tag
             </code></pre></div>