title: Sorting data by type in R
body: <p>I am struggling to write a function for a dataset that looks like this:   </p>
  
  <pre><code>identifier   age   occupation        
  pers1        18    student   
  pers2        45    teacher   
  pers3        65    retired   
  </code></pre>
  
  <p>What I am trying to do, is to write a function that will:</p>
  
  <ol>
  <li>sort my variables into numerical vs. factor variable</li>
  <li>for the numerical variables, give me the mean, min and mx</li>
  <li>for the factor variable, give me a frequency table</li>
  <li>return point (2) and (3) in a "nice" format (dataframe, vector or table)</li>
  </ol>
  
  <p>So far, I have tried this:</p>
  
  <pre><code>describe&lt;- function(x) 
  { if (is.numeric(x)) { mean &lt;- mean(x)
                     min &lt;- min(x)
                     max &lt;- max(x) 
                     d &lt;- data.frame(mean, min, max)}
    else { factor &lt;- table(x) }
  }
  stats &lt;- lapply(data, describe)
  </code></pre>
  
  <p>Problems:
  My problem is that now, "stats" is a list that is difficult to read and to export to Excel or share. I don't know how to make the list "stats" more reader-friendly.</p>
  
  <p>Alternatively, maybe is there a better way to build the function "describe"?</p>
  
  <p>Any thoughts on how to solve these two problems are much appreciated!</p>