title: R - lapply() Returning Null Values in Data Frame
body: <p>I have a data frame, <strong>util_final</strong> with a column, <em>utilization_Ratio</em> I would like to use to assign categorical values.</p>
  
  <p>The data frame has the following structure:</p>
  
  <pre><code>$ Patient_ID       : Factor w/ 3242 levels "0000001C-89D2-40FF-868D-8E1B4C8C9114",..: 1 2 3 4 5 6 7 8 9 10 ...
   $ OP               : num  1 11 2 1 5 6 12 8 10 6 ...
   $ IP               : num  2 0 0 1 1 3 4 5 0 3 ...
   $ Total            : num  3 11 2 2 6 9 16 13 10 9 ...
   $ utilization_Ratio: num  0.667 0 0 0.5 0.167 ...
  </code></pre>
  
  <p>I've created this function to define the aforementioned categorical values:</p>
  
  <pre><code>assign_risk_factor=function(x) {
    for(i in util_final$utilization_Ratio) {
      if(i&lt;0.33) {
        print("Low")
      } else if(i&gt;0.67) {
        print("High")
      } else {
        print("Medium")
      }
    } 
  }
  </code></pre>
  
  <p>I then tried to use lapply() to connect the function with the data frame, inserting the categorical variable defined in the function in a new column in the data frame:</p>
  
  <pre><code>util_final$Risk_Factor=lapply(util_final$utilization_Ratio,assign_risk_factor)
  </code></pre>
  
  <p>That, indeed, creates the new column, but it simply inserts a "NULL" in each row of the column, like so:</p>
  
  <pre><code>Patient_ID OP IP Total utilization_Ratio Risk_Factor
  0000001C-89D2-40FF-868D-8E1B4C8C9114 0000001C-89D2-40FF-868D-8E1B4C8C9114  1  2     3         0.6666667        NULL
  001B8544-508E-4CBE-A40A-EAAD97E541BE 001B8544-508E-4CBE-A40A-EAAD97E541BE 11  0    11         0.0000000        NULL
  00336A6F-93D8-42F6-B2E5-A1EF12C2BD75 00336A6F-93D8-42F6-B2E5-A1EF12C2BD75  2  0     2         0.0000000        NULL
  0039B0C1-E84F-4B90-AD9B-985C9F39ABD1 0039B0C1-E84F-4B90-AD9B-985C9F39ABD1  1  1     2         0.5000000        NULL
  003E8473-C645-4AF2-B48A-86BE76188CC5 003E8473-C645-4AF2-B48A-86BE76188CC5  5  1     6         0.1666667        NULL
  00765CEF-B05C-471F-B91F-8154E6158486 00765CEF-B05C-471F-B91F-8154E6158486  6  3     9         0.3333333        NULL
  </code></pre>
  
  <p>The part that really confuses me: when I run the lapply() function, the console seems to show the categorical variables producing as expected (in other words, suggesting the For Loop I created works).  However, again, the resulting new column of my data frame only contains NULL's.</p>
  
  <p>Thank you!</p>