I am very new with R, so hoping I can get some pointers on how to achieve the desired manipulation of my data.
I have an array of data with three variables.
gene_id fpkm meth_val
1 100629094 0.000 0.0063
2 100628995 0.000 0.0000
3 102655614 111.406 0.0021
I'd like to plot the average meth_val after stratifying my gene_ids based on fpkm into quartiles or deciles.
Once I load my data into a dataframe...
data <- read.delim("myfile.tsv", sep='\t')
I can determine the fpkm deciles using:
quantile(data$fpkm, prob = seq(0, 1, length = 11), type = 5
which yields
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
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.
The main thing I'm really stuck on is how to split my dataset in the proper way. Any assistance would be hugely appreciated!
Thanks a bunch!