title: Writing an ifelse statement with a paste function in for-loop in R
body: <p>So I have 50 variables with value range from 1 to 4, and I want to count how many are 1 or 2 and how many are 3 or 4.</p>
  
  <p>i.e. abc1=2, abc2=2, ... abc50=3</p>
  
  <p>and the following is my code</p>
  
  <pre><code>#Create new variable to store the counted number to
  
  abc.low=0
  abc.high=0
  </code></pre>
  
  <p>And here is the code I am stuck at (it doesn't work)</p>
  
  <pre><code>for (i in 1:50){
  ifelse (paste("abc",i,sep="")==1|paste("abc",i,sep="")==2, 
  (abc.low&lt;-abc.low&lt;-1),(abc.low&lt;-abc.low))
  }
  
  for (i in 1:50){
  ifelse (paste("abc",i,sep="")==3|paste("abc",i,sep="")==4, 
  (abc.high&lt;-abc.high&lt;-1),(abc.high&lt;-abc.high))
  }
  </code></pre>
  
  <p>I am assuming the paste function is not appropriate in what I am trying to do. </p>
  
  <p>i.e)</p>
  
  <pre><code>abc1=3
  
  abc1==3
  #True
  
  paste("abc",1,sep="")==3
  # False
  </code></pre>
  
  <p>where the paste function should return true for my purpose.</p>
  
  <p>I appreciate your input!</p>