title: stacking columns into 1 column in R
body: <p>I have a data frame that looks like: </p>
  
  <pre><code>ID Time U1 U2 U3 U4 ...
  1  20    1  2 3  5 .. 
  2  20    2  5 9  4 ..
  3  20    2  5 6  4 ..
  .
  .
  
  And I would need to keep it like: 
  
  ID Time  U
  1  20    1
  1  20    2
  1  20    3
  1  20    5
  2  20    2
  2  20    5
  2  20    9
  2  20    4
  3  20    2
  3  20    5
  3  20    6
  3  20    4
  </code></pre>
  
  <p>I tried with: </p>
  
  <pre><code>X &lt;- read.table("mydata.txt", header=TRUE, sep=",")
  X_D &lt;- as.data.frame(X)
  X_new &lt;- stack(X_D, select = -c(ID, Time))
  </code></pre>
  
  <p>But I haven't managed to get the data into that form. Honestly, I have little experience with stacking/transposing, so any help is greatly appreciated!</p>