Create dataframe from unique vectors of differing lengths in R?
<p>I have an R dataframe, titled <code>tab</code>, like the following:</p>

<pre><code>StoreID    Sales    ZIP    day
1          4900     55401  1/1/1993
1          3121     55401  1/2/1993
3          10021    90210  1/1/1993
3          50000    90210  1/2/1993
13         12000    12312  1/1/1993
</code></pre>

<p>...</p>

<p>The number of unique <code>StoreID</code> values is 40, while the number of unique <code>ZIP</code> values is 25. I basically want a dataframe of length 40, with just the StoreID and ZIP codes.</p>

<p>This is basically what I've tried:</p>

<pre><code>ID_ZIP &lt;- data.frame(unique(tab$StoreID))
for(i in unique(tab$StoreID)){
  dat &lt;- tab[StoreID == i]
  append(unique(tab$Zip))
}
</code></pre>

<p>And I've kind of gotten stuck. I'm used to key-value iterations in Python.. Would <code>merge</code> be the right way?</p>

<p>Edit:
The result set:</p>

<pre><code>StoreID    ZIP
1          55401
3          90210
13         12312
</code></pre>

<p>...</p>