r - Using cut2 from Hmisc to calculate cuts for different number of groups -
i trying calculate equal quantile cuts vector using cut2 hmisc.
library(hmisc) c <- c(-4.18304,-3.18343,-2.93237,-2.82836,-2.13478,-2.01892,-1.88773, -1.83124,-1.74953,-1.74858,-0.63265,-0.59626,-0.5681) cut2(c, g=3, onlycuts=true) [1] -4.18304 -2.01892 -1.74858 -0.56810
but expecting following result (33%, 33%, 33%):
[1] -4.18304 -2.13478 -1.74858 -0.56810
should still use cut2 or try different? how can make work? advice.
you seeing cutpoints, want tabular counts, , want them fractions of total, instead:
> prop.table(table(cut2(c, g=3) ) ) [-4.18,-2.019) [-2.02,-1.749) [-1.75,-0.568] 0.3846154 0.3076923 0.3076923
(obviously cannot expect cut2 create exact split when count of elements not evenly divisible 3.)
Comments
Post a Comment