3
$\begingroup$

I have some data:

x <- c(0.0636931012704989, 0.0421033586843369, 0.0214721845269228, 
0.038624779052474, 0.033235347720021, 0.0307709640052774, 0.0606316442337883, 
0.0289958997354256, 0.0573689255248752, 0.044448618126441, 0.0164384406368751, 
0.0357802024114138, 0.0133831663454831, 0.0329126088838874, 0.051468481535772, 
0.0302927520748979, 0.169023097551101, 0.0311182034472608, 0.117954563949638, 
0.0593735124639249, 0.0110273691186214, 0.0286868155187407, 0.0522496344459376, 
0.0298854332250777, 0.0626024185545931, 0.106914814257457, 0.0396392209572767, 
0.0111988702332617, 0.0276848766950444, 0.0142151606082234)

I would like to find the values, in R preferably, in order to split x equally numbered groups.

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Use the quantiles:

ngroups <- 3
q <- quantile(x, 0:ngroups/ngroups)
sprintf("The boundaries of the %d groups are: %s", groups, paste(signif(q, 3), collapse=", "))
# Or simply:
q

You can then cut:

cut.x <- cut(x, breaks=q, include.lowest=TRUE)
table(cut.x)
# Or split if you want to keep the exact numeric values:
split(x, cut.x)
$\endgroup$
2
  • $\begingroup$ Thank you. Perfect. Just how do I access the values? I tried table(cut.x)[1][1], etc, but cannot find a value directly. $\endgroup$ Jan 30, 2014 at 16:22
  • 1
    $\begingroup$ The cut points are in q. I added some information to show them. Also if you want to keep the numeric data you can use split. There are thousands of ways to use this. $\endgroup$
    – Calimo
    Jan 30, 2014 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.