# Find the values that let me split x in equally numbered groups

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.

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)

• Thank you. Perfect. Just how do I access the values? I tried table(cut.x)[1][1], etc, but cannot find a value directly. Commented Jan 30, 2014 at 16:22
• 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. Commented Jan 30, 2014 at 16:59