title: R: splitting dataset into quartiles/deciles. What is the right method?
body: <p>I am very new with R, so hoping I can get some pointers on how to achieve the desired manipulation of my data. </p>
  
  <p>I have an array of data with three variables.</p>
  
  <pre><code>  gene_id       fpkm  meth_val
  1 100629094     0.000 0.0063
  2 100628995     0.000 0.0000
  3 102655614   111.406 0.0021
  </code></pre>
  
  <p>I'd like to plot the average meth_val after stratifying my gene_ids based on fpkm into quartiles or deciles.</p>
  
  <p>Once I load my data into a dataframe...   </p>
  
  <pre><code>data &lt;- read.delim("myfile.tsv", sep='\t')
  </code></pre>
  
  <p>I can determine the fpkm deciles using:</p>
  
  <pre><code>quantile(data$fpkm, prob = seq(0, 1, length = 11), type = 5
  </code></pre>
  
  <p>which yields</p>
  
  <pre><code>          0%          10%          20%          30%          40%          50%
  0.000000e+00 9.783032e-01 7.566164e+00 3.667630e+01 1.379986e+02 3.076280e+02
           60%          70%          80%          90%         100%
  5.470552e+02 8.875592e+02 1.486200e+03 2.974264e+03 1.958740e+05
  </code></pre>
  
  <p>From there, I'd like to essentially split the dataframe into 10 groups based on whether the fpkm_val fits into one of these deciles. Then I'd like to plot the meth_val of each decile in ggplot as a box plot and perform a statistical test across deciles.</p>
  
  <p>The main thing I'm really stuck on is how to split my dataset in the proper way. Any assistance would be hugely appreciated!</p>
  
  <p>Thanks a bunch!</p>