title: Transform R dataframes using variables in loop
body: <p>I am trying to replace values in a R dataframe by column. I would like to loop though a given list of columns of the dataframe and replace all "Yes" values by 1 and all the other values by 0.</p>
  
  <p>I tried to do this using transform() and ifelse() functions with the something like this:</p>
  
  <pre><code># List of selected Columns:
  ColumnNames = c("Frigori", "Microond" , "Arca", "Aspira")
  
  # Replace Values in dataframe
  for(i in 1:length(ColumnNames)){
  dataframe &lt;- transform(dataframe, ColumnNames[i] = ifelse(Columnames[i] == "Yes", 1, 0))
  }
  </code></pre>
  
  <p>This piece of code works fine with explicit column names outside the loop, but with the array it will give me the following error:</p>
  
  <pre><code>Error: unexpected '=' in:
  "for(i in 1:length(Appliances)){
  dataframe &lt;- transform(dataframe, ColumnNames[i] ="
  </code></pre>
  
  <p>I don't know what goes wrong here, but the problem has to be related with the variable substitution.</p>