title: how to get class of a variable in R using loop?
body: <p>I have data frame in R with four columns and I am trying to get class of each variable using for loop, depending on a class of variable I could write a further code. Below is the data frame.</p>
  
  <pre><code>   var1 var2 var3 var4
  1     1    a    a    s
  2     2    g    a    s
  3     3    b         s
  4     4    n    s    s
  5    NA    m    f    f
  6     6    r    g    v
  7     7    t         b
  8     8         j     
  9     9    y    i    g
  10   10    h    i    t
  </code></pre>
  
  <p>As of now I have tried below code but it is giving NULL for a class of variable</p>
  
  <pre><code>for (i in names(df)){
    print(names(df[i]))
    name &lt;- names(df[i])
    print(class(df$name))
  }
  </code></pre>
  
  <p>Result with above code:</p>
  
  <pre><code>[1] "var1"
  [1] "NULL"
  [1] "var2"
  [1] "NULL"
  [1] "var3"
  [1] "NULL"
  [1] "var4"
  [1] "NULL"
  </code></pre>
  
  <p>Expecting Result</p>
  
  <pre><code>    [1] "var1"
      [1] "integer"
      [1] "var2"
      [1] "factor"
      [1] "var3"
      [1] "factor"
      [1] "var4"
      [1] "integer"
  </code></pre>
  
  <p>Requesting your help.</p>