# Determine minimum acceptable step in cut()

I'm using cut() to transform data like this:

N <- 10
table(cut(iris$Sepal.Length,quantile(iris$Sepal.Length,probs=seq(0,1,1/N))))


However, I do have many variables and I would like to determine what is the maximum acceptable N for variable. I thought this will be linked to unique values, but it is not that easy:

length(unique(iris$Sepal.Length)) # 35 unique values N <- 19 ## Fails if N > 19 table(cut(iris$Sepal.Length,quantile(iris\$Sepal.Length,probs=seq(0,1,1/N))))


Is there a way how to calculate N or do I have to find this number iteratively?

Maybe this will be simpler case to work with:

N <- 4
x <- c(1,2,2,2,2,2,2,2,3,3,3,3,4,5,6,7,8)
table(cut(x,quantile(x,probs=seq(0,1,1/N))))

• What's your goal with the transformed data? – Thomas Jul 26 '13 at 9:02
• I would like to use this as input to understand/plot relationship between variable and binary predictor. – Tomas Greif Jul 26 '13 at 9:07
• Why not look at the raw data? – Thomas Jul 26 '13 at 9:10
• The quantiles need to be unique. If the quantiles are unique depends on the data and the probabilities (the latter being calculated from N). The algorithm used by quantile is not exactly easy to understand and I don't think it is easily possible to predict if the quantiles are unique without calculating them. – Roland Jul 26 '13 at 9:13
• I suggest to change your question to something like "How to calculate the maximum number of equidistant probability values from 0 to 1 that result in unique sample quantiles". That would make it a better fit for CV and is an interesting problem. – Roland Jul 26 '13 at 9:46