title: R levels function returning NULL by calling dataset column
body: <p>I'm trying to find levels of a specific column in a dataset.</p>
  
  <p>Suppose I have a dataset as below:</p>
  
  <pre><code>    df
      apple    orange
        1        3
        2        4
        4        7
        3        1
        2        4
        .        3
        1        2
  </code></pre>
  
  <p>In my original dataset, column apple is structured as of the following displayed in console:</p>
  
  <pre><code>  &lt;chr&gt;          
     1 7              
     2 2              
     3 4              
     4 1              
     5 1              
     6 6              
     7 5              
     8 2              
     9 4              
     10 2              
     # ... with 17,273 more rows
  </code></pre>
  
  <p>I made sure that each column is converted to factor and rid of missings by the following function:</p>
  
  <pre><code>    convert_missing &lt;- function(x){
  
         column &lt;- as.character(x)
         column[is.na(column)] &lt;- "Missing_"
         column &lt;- as.factor(column)
         column &lt;- factor(column, levels(column)[order(as.numeric(levels(column)))])
         return(column)
      }
  </code></pre>
  
  <p>then if I pass a column in df to convert_missing and to extract levels of the column I'm not sure why I always receive NULL as the outcome, such as:</p>
  
  <pre><code>  df_vars &lt;- list()
    df["apple"] &lt;-lapply(df["apple"],convert_missing)
    df_vars[["DV_Levels"]] &lt;- levels(df[, "apple"]) #this returns NULL
  </code></pre>
  
  <p>Any help will be appreciated! </p>