title: R: Transpose variables in column into row by date
body: <p>[Solution] I found my own solution to the problem.</p>
  
  <pre><code>  require(data.table)
    dt &lt;- data.table(dataframe)
    newdt&lt;-dt[, number := 1:.N, by = Date] 
    data&lt;-as.data.frame(newdt)
  
  data_wide &lt;- reshape(newdt, direction="wide", idvar = "Date", timevar =   "number")
  
  data_wide
  
  6/26/2015   209.3     230.2     80.4     s2
  6/27/2015   209.1     227.2     239.2    s2
  </code></pre>
  
  <p>Edit 2: I think that the solution provided by others would work if I can figure out how to create a new column in my original dataframe that <strong>labels</strong> the number of the rows (or valid values in Variable 1) for each date. In other words, I would like to restart labeling rows at each change in date. For example,</p>
  
  <pre><code>6/26/2015   1   209.3
  6/26/2015   2   230.2
  6/26/2015   3   80.4
  6/26/2015   4   s2
  6/27/2015   1 ....
  </code></pre>
  
  <p>And then I could use the reshape methods described in the other posts.</p>
  
  <p>Edit: This is close to <a href="https://stackoverflow.com/questions/5890584/reshape-data-from-long-to-wide-format-r">How to reshape data from long to wide format?</a>, but in order for those answers to fit my data I would need a new column here that assigns a number 1-length variable 1 for each day to the variables, which I don't have.</p>
  
  <p>In other words, if I use</p>
  
  <pre><code>data_wide &lt;- reshape(data,direction="wide", idvar = "Date", timevar = "Variable 1")
  data_wide
  </code></pre>
  
  <p>Then, because there are 200+ unique entries for Variable 1, data_wide had 200+ columns for each date, with most of those being na because values for Variable 1 typically only exist on a single date in the data, and the data is a time series of over 5000 dates.
  ~~~~~~~~~~~~</p>
  
  <p>I have a dataframe where column 1 = <code>Date</code> and column 2 = <code>Variable 1</code> where Variable 1 is usually numeric. E.g.</p>
  
  <pre><code>6/26/2015   209.3    
  6/26/2015   230.2    
  6/26/2015   80.4     
  6/26/2015   s2       
  6/27/2015   209.1    
  6/27/2015   227.2    
  6/27/2015   239.2    
  6/27/2015   s2       
  </code></pre>
  
  <p>I would like to be able to label the rows with a new value that is simply the row number for that date.</p>
  
  <pre><code>6/26/2015   209.3    1
  6/26/2015   230.2    2
  6/26/2015   80.4     3
  6/26/2015   s2       4
  6/27/2015   209.1    1
  6/27/2015   227.2    2
  6/27/2015   239.2    3
  6/27/2015   s2       4
  </code></pre>
  
  <p>[Original Post]</p>
  
  <p>I have a dataframe where column 1 = <code>Date</code> and column 2 = <code>Variable 1</code> where Variable 1 is usually numeric. E.g.</p>
  
  <pre><code>6/26/2015   209.3
  6/26/2015   230.2
  6/26/2015   80.4
  6/26/2015   s2
  6/27/2015   209.1
  6/27/2015   227.2
  6/27/2015   239.2
  6/27/2015   s2
  6/28/2015   230.2
  6/28/2015   228.2
  6/28/2015   36.4
  6/28/2015   s2
  6/29/2015   209.3
  6/29/2015   15.3
  6/29/2015   15.4
  6/29/2015   s2
  </code></pre>
  
  <p>I would like to be able to "transpose" the data such that each date has its own row, and each Variable for the same date is in the same row. E.g.</p>
  
  <pre><code>6/26/2015   209.3     230.2     80.4     s2
  6/27/2015   209.1     227.2     239.2    s2
  </code></pre>
  
  <p>And so on. Although this example shows the same number of entries for Variable 1 per date, this is not always the case. I would like to be able to allow for any number of Variables to be collapsed onto the date.</p>
  
  <p>A complicating factor is that there are actually two more columns, Variable 2 and Variable 3, which are constant within a date but may vary between two dates. I would like those to be collapsed onto the date as well, but I only need one column for each of these variables in the new dataframe.</p>
  
  <p>I have tried using dcast and reshape functions, but these do not give the intended result. Does anyone have suggestions?</p>