r - calculate frequency of one category based on selected variable
<p>I have a data frame called <strong>stats</strong> with two columns <strong>Gender</strong> and <strong>Transportation.used</strong> as shown below:</p>

<pre><code>Gender    Transportation.used
Male      Bus
Male      Car
Female    Car
Male      Car
Male      Motorcycle
Female    Bus
</code></pre>

<p>and the list go on.. (or view here: <a href="http://i.stack.imgur.com/GROIi.jpg" rel="nofollow">http://i.stack.imgur.com/GROIi.jpg</a>)</p>

<pre><code>data_stats &lt;- read.table(text="Gender   Transportation.used
Male    Bus
Male    Car
Female  Car
Male    Car
Male    Motorcycle
Female  Bus
Female  Bus
Female  Bus
Female  Bus
Male    Car
Female  Car
",header=T)
</code></pre>

<p>What I wanna do is to calculate the frequency for gender based on the <strong>selected transport</strong>. I will need the data later on to plot a percentage bar graph. Desired output as below:</p>

<pre><code>          Male    Female
   Bus    1        4
</code></pre>

<p>So how do I calculate in order to get the data? I'm still a beginner in using R, please do help me. Thanks in advance!</p>