title: How to reshape a matrix
body: <p>I have a matrix (d) that looks like:</p>
  
  <pre><code>d &lt;- 
  as.matrix(read.table(text = "
      month    Q1    Q2   Q3    Q4    Q5    Q6    Q7    Q8    Q9   Q10   Q11   Q12   Q13         
  X10    10  7.04  8.07  9.4  8.17  9.39  8.13  9.43  9.06  8.59  9.37  9.79  8.47  8.86  
  X11    11 12.10 11.50 12.6 13.70 11.90 11.50 13.10 17.20 19.00 14.60 13.70 13.20 16.10  
  X12    12 24.00 22.00 22.2 20.50 21.60 22.50 23.10 23.30 30.50 34.10 36.10 37.40 28.90 
  X1      1 18.30 16.30 16.2 14.80 16.60 15.40 15.20 14.80 16.70 14.90 15.00 13.80 15.90  
  X2      2 16.70 14.40 15.3 14.10 15.50 16.70 15.20 16.10 18.00 26.30 28.00 31.10 34.20",
  header=TRUE))
  </code></pre>
  
  <p>going from Q1 to Q31 (its the days in each month). what I would like to get is:</p>
  
  <pre><code>month day Q
  10    1   7.04
  10    2   8.07
  </code></pre>
  
  <p>and so on for the 31 days and the 12 months.</p>
  
  <p>I have tried using the following code:</p>
  
  <pre><code>reshape(d, direction="long", varying = list(colnames(d)[2:32]), v.names="Q", idvar="month", timevar="day") 
  </code></pre>
  
  <p>but I get the error :</p>
  
  <p><code>Error in d[, timevar] &lt;- times[1L] : subscript out of bounds</code></p>
  
  <p>Can anyone tell me what is wrong with the code? I don't really understand the help file on "reshape", it's a bit confusing... Thanks!</p>