title: Comparison (1) in R function returns possible only for atomic or list types
body: <p>I have the following function:</p>
  
  <pre><code> agegroup &lt;- function(data, column) {
  
   setDT(data)
  
   if (class(data[[column]] == "integer")) {
  
    data[column &lt;20, agegroup := "0-19"]
    data[column &gt;= 20 &amp; column &lt; 25, agegroup := "20-24"]
    data[column &gt;= 25 &amp; column &lt;30, agegroup := "25-29"]
    data[column &gt;= 30 &amp; column &lt;35, agegroup := "30-34"]
    data[column &gt;= 35 &amp; column &lt;40, agegroup := "35-39"]
    data[column &gt;= 40 &amp; column &lt;45, agegroup := "40-44"]
    data[column &gt;= 45 &amp; column &lt;50, agegroup := "45-49"]
    data[column &gt;= 50 &amp; column &lt;55, agegroup := "50-54"]
    data[column &gt;= 55 &amp; column &lt;60, agegroup := "55-59"]
    data[column &gt;= 60 &amp; column &lt;65, agegroup := "60-64"]
    data[column &gt;= 65 &amp; column &lt;70, agegroup := "65-69"]
    data[column &gt;= 70 &amp; column &lt;75, agegroup := "70-74"]
    data[column &gt;= 75 &amp; column &lt;80, agegroup := "75-79"]
    data[column &gt;= 80 &amp; column &lt;85, agegroup := "80-84"]
    data[column &gt;= 85, agegroup := "85+"]
  
    return(data)
  
    } else {
  
      print("Column type is not integer.")
  
    }
  }
  </code></pre>
  
  <p>The function should check whether the referenced column is of integer type. However, when I do the comparison I get the following error: </p>
  
  <pre><code>Error in data[[column]] == integer : 
    comparison (1) is possible only for atomic and list types
  </code></pre>
  
  <p>Edit: </p>
  
  <p>I placed the original function above.</p>
  
  <p>Also, Sample of the data: </p>
  
  <pre><code>structure(list(age = c(87L, 70L, 69L, 68L, 68L, 68L)), class = c("data.table", 
  "data.frame"), row.names = c(NA, -6L))
  </code></pre>
  
  <p>Function call:</p>
  
  <pre><code>test &lt;- agegroup(test, "age")
  </code></pre>
  
  <p>I'm not sure what is the problem. </p>