title: Using a variable to refer to another variable in R?
body: <p>I am trying to run a "for" loop in R to analyze multiple variables. I have a data set ("DataSet") with column names ("AppleTag1", "AppleTag2", "CherryTag1", "CherryTag2"....). The loop is to compare "Tag1" with "Tag2" columns for each unique column name listed in "ColumnName" and obtain a vector with unique values from both columns. My question is how do I refer to the result of a paste function as a variable. I know the first past function used to collect the unique results can be fixed with "align()". However, what about the other two? How can I make sure R analyzes the paste() result "DataSet$AppleTag1" as a variable and not as a "string". Right now, I get a list of "CombineResult_XXX" with "DataSet$AppleTag1, DataSet$AppleTag2," yet I want is for it to test what is inside these two columns and get something like "123, 213, 141, 232".
  Thank you for your help.</p>
  
  <pre><code>ColumnName &lt;- c("Apple","Cherry","Bubble","Killer","Fat","Glass","Comp","Key")
  NameTag &lt;- c(A,B,C,D,E,F,G,H,I,J)
  for (i in 1:10) {
    paste("CombineResult_",NameTag[i],sep="") &lt;- unique(c(
    as.vector(paste("DataSet$",ColumnName[i],"Tag1", sep="")),
    as.vector(paste("DataSet$",ColumnName[i],"Tag2", sep=""))))
  }
  </code></pre>