you can try using Hmisc
library and cut2
function. You can cut vector into different groups by stating the cutpoints. Here is an example:
library(Hmisc)
data <- data.frame(gene_id=sample(c("A","B","D", 100), 100, replace=TRUE),
fpkm=abs(rnorm(100, 100, 10)),
meth_val=abs(rnorm(100, 10, 1)))
quantiles <- quantile(data$fpkm, prob = seq(0, 1, length = 11), type = 5)
data$cutted <- cut2(data$fpkm, cuts = as.numeric(quantiles))
And you will get the same data frame with additional columns for split:
gene_id fpkm meth_val cutted
1 B 102.16511 8.477469 [100.4,103.2)
2 A 110.59269 9.256172 [106.4,110.9)
3 B 93.15691 10.560936 [ 92.9, 95.3)
4 B 105.74879 10.301358 [103.2,106.4)
5 A 96.12755 11.336484 [ 95.3, 96.8)
6 B 106.29204 8.286120 [103.2,106.4)
...
Moreover you can cut using cut2
specifying by quantiles groups too. Read more ?cut2
.