1

I have an R script that I am using to create a new data matrix consisting of bin values from a matrix of continuous data. Right now it works fine using this command:

quant.mat <- apply(input.dat,2,quantile)

But this gives me the standard quantile distribution of 0.25, 0.5, and 0.75. What I want is to be able to arbitrary specify different values (e.g. 0.2, 0.4, 0.6, 0.8). I can't seem to make it work.

Psidom
  • 209,562
  • 33
  • 339
  • 356
Wolfgang
  • 80
  • 5
  • Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete and verifyible example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Perhaps the following tips on [asking a good question](http://stackoverflow.com/help/how-to-ask) may also be worth a read. – lmo Jun 14 '16 at 19:18

2 Answers2

2

You can pass arbitrary probability values to the probs parameter, for example, if you have a random data frame:

input.dat
   A  B  C  D
1 78 12 43 12
2 23 12 42 13
3 14 42 11 99
4 49 94 27 72

apply(input.dat, 2, quantile, probs = c(0.2, 0.4, 0.6, 0.8))
       A    B    C    D
20% 19.4 12.0 20.6 12.6
40% 28.2 18.0 30.0 24.8
60% 43.8 36.0 39.0 60.2
80% 60.6 62.8 42.4 82.8
Psidom
  • 209,562
  • 33
  • 339
  • 356
1

you can pass the cuts that you like to the quantile function. For example:

values<-runif(100,0,1)
quantile(values, c(0.2,0.4,0.6,0.8))

Does it answer your question?

Matias Thayer
  • 571
  • 3
  • 8