title: How to write loop for creating multiple variables in R
body: <p>I have a data set in R called <code>data</code>, and in this data set I have more than 600 variables. Among these variables I have 94 variables called <code>data$sleep1,data$sleep2...data$sleep94</code>, and another 94 variables called <code>data$wakeup1,data$wakeup2...data$wakeup94</code>. </p>
  
  <p>I want to create new variables, <code>data$total1-data$total94</code>, each of which is the sum of <code>sleep</code> and <code>wakeup</code> for the same day.</p>
  
  <p>For example, <code>data$total64 &lt;-data$sleep64 + data$wakeup64</code>,<code>data$total94&lt;-data$sleep94+data$wakeup94</code>.</p>
  
  <p>Without a loop, I need to write this code 94 times. I hope someone could give me some tips on this. It doesn't have to be a loop, but an easier way to do this. </p>
  
  <p>FYI, every variables are numeric and have about 30% missing values. The missing are random, it could be anywhere. missing value is a blank but not 0.  </p>