title: Wide to Long with Two sets of Variables to Reshape
body: <p>I have a dataset containing 4 dependent variables, 6 independent variables, and 9 covariates. The dataset is arranged in wide format.</p>
  
  <p>I wish to make it in long format, so I can repeat a certain procedure (lm, plot, ...) in a loop, varying the dependent variable and the independent, while keeping the covariates (in lm example).</p>
  
  <p>The data I have looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/ZSFA6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZSFA6.png" alt="enter image description here"></a></p>
  
  <p>And I want it like:</p>
  
  <p><a href="https://i.stack.imgur.com/22hPy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/22hPy.png" alt="enter image description here"></a></p>
  
  <p>If I had only one set of variables (dependent only or independent only), I know how to do it, I would use the <strong>reshape</strong> function. But how do I do it when I have two sets of variables ? I need to create 24 different combinations of DV and IV while keeping all covariates in every row.</p>
  
  <p>Would appreciate some guidance. Thank you in advance !</p>
  
  <p>Code for generating random data in the shape of my data:</p>
  
  <pre><code>ID = seq(1,5)
  DV1 = rnorm(5,0,1)
  DV2 = rnorm(5,0,1)
  DV3 = rnorm(5,0,1)
  DV4 = rnorm(5,0,1)
  IV1 = rnorm(5,0,1)
  IV2 = rnorm(5,0,1)
  IV3 = rnorm(5,0,1)
  IV4 = rnorm(5,0,1)
  IV5 = rnorm(5,0,1)
  IV6 = rnorm(5,0,1)
  COV1 = rnorm(5,0,1)
  COV2 = rnorm(5,0,1)
  COV3 = rnorm(5,0,1)
  data = data.frame(ID,DV1,DV2,DV3,DV4,IV1,IV2,IV3,IV4,IV5,IV6,COV1,COV2,COV3)
  </code></pre>