title: create new variables using for loop and if condition
body: <p>I have a data frame as below</p>
  
  <pre><code>head(sip1)
  
     ID INTERVIEWDATE SS1 SS2 SS2b SS3 SS4_1 SS4_2 SS4_3 SS4_4 SS4_5 SS4_6 SS4_7 SS4_8 SS4_9 SS4_10 SS4_11 SS4_12 SS4_13 SS4_14 SS4_15 SS4_16 SS4_17 SS4_18 SS4_19 SS4_20 SS4_21 SS4_22
  1  1    2014-03-19   4   1    1   2     1     1     4     1     1     1     1     1     1      1      1      1      1      1      1      1      3      1      1      1      1      1
  2  2    2014-03-19   2   1    5   1     1     1     1     1     1     1     2     1     1      1      1      1      1      1      4      1      1      1      1      1      1      1
  3  3    2014-03-19   3   1    8   2     1     1     1     4     1     1     4     1     1      1      1      1      1      1      1      1      1      1      1      1      1      1
  4  4    2014-03-18   3   1    5   1     1     1     1     1     1     1     1     1     3      1      1      1      1      1      1      1      1      1      1      1      1      1
  5  5    2014-03-18   3   1    8   1     1     1     1     1     1     1     1     1     3      1      1      1      1      2      1      1      1      1      1      1      1      1
  6  6    2014-03-19   3   1    1   2     1     1     1     1     1     1     1     1     3      1      1      3      1      3      1      1      1      1      1      1      1      1
  
        SS4_23 SS4_24 SS4_25 SS4_26 SS4_27 SS4_28 SS4_29 SS4_30 SS5 SS6 SS7 HS1_C1_A HS1_C1_B HS1_C1_C HS1_C1_D HS1C1
      1      1      1      1      1      1      1      1      1   1   2   2        1        2        2        2     1
      2      1      1      1      1      1      1      1      1   1   2   2        2        2        2        2     0
      3      1      1      1      1      1      1      1      1   1   2   2        1        2        2        2     1
      4      1      1      1      1      1      1      1      1   2   2   2        1        2        2        2     1
      5      1      1      1      1      1      1      1      1   1   2   2        2        2        2        2     0
      6      1      1      1      1      1      1      1      1   1   2   2        1        2        2        2     1
  </code></pre>
  
  <p>Here I want to create a series of new variables (eg. <code>newSS4_1</code>，<code>newSS4_2</code>，<code>newSS4_3</code>...<code>newSS4_30</code>)regarding to <code>SS4_1</code>...<code>SS4_30</code>, using the condition that <code>newSS4_1 [SS4_1==1] &lt;- 0; newSS4_1 [SS4_1!=1] &lt;- 1</code>. I want to make the 30 variables to binomial following the condition: if the old value=1, the new value=0; if the old value!=1, the new value=1. And create them as new variables. </p>
  
  <p>Could anyone please help? i have no idea how to do this in loop to write 30 new variables, and how to use if conditions?</p>
  
  <p>Thanks,qiqi</p>