title: R check if a variable is a factor
body: <p>I am trying to write a loop which can apply to a dataframe.  The loop will basically check each variable in the dataframe and tell me which variable is a factor.</p>
  
  <p>An example:</p>
  
  <pre><code>test1&lt;-c("red","red","blue","yellow")
  test1&lt;-as.factor(test1)
  test2&lt;-c(1,2,3,4)
  
  variable&lt;-c("test1","test2")
  count&lt;-2
  
  for (i in 1:count)
  {
          if (is.factor(paste(variable[i]))==TRUE) 
          { 
             print("This is a factor")
          }
  }
  </code></pre>
  
  <p>test1 variable is supposed to be a factor and therefore the sentence "This is a factor" should be printed.  However nothing happened.  I wonder why?</p>