title: Apply function for survival analysis
body: <p>I have a dataframe with patient data/ survival and with gene expression data looking like this</p>
  
  <pre><code># Patients event time Gene_1 ... Gene_100
  1 Patient_1 1 356 3455 ... 59393
  2 Patient_2 1 1233 6632 ... 43299
  3 Patient_3 0 1224 3636 ... 44222
  4 Patient_4 0 56 30603 ... 23999
  ...
  100 Patient_100 1 853 ... 25888
  </code></pre>
  
  <p>What I did was writing a function that is subsetting the gene expression data of each single gene (e.g. Gene_1) into quartiles, and then picking the lowest and highest quartile for comparison in survival analysis:</p>
  
  <pre><code>library(dplyr); library(survival)
  quartile_function &lt;- function(dataframe, column_x){
     dataframe$quartile &lt;- ntile(dataframe[ ,column_x], 4)
     dataframe &lt;- subset(dataframe, quartile == 1 | quartile == 4)
     group &lt;- dataframe$quartile
     coxph( Surv(time, event) ~ group, data=dataframe )[['coefficients']]
  }
  </code></pre>
  
  <p>Then I do a cox proportional hazard analysis, where I'm only interested in <code>coef</code></p>
  
  <p>That all works when I pick  the genes column by column, but I struggle to apply  this function to every column  containing gene expression data in the dataframe.</p>
  
  <p>Any ideas to do this more efficiently?  And how can I apply this function easily to every column with Gene expression data, so that I get an overview of the coef for every gene?</p>