# Partitioning a sequence of numbers based on a percentage

I have a sequence $s$ of rational numbers where $|s|=n$. I am given a percentage $p$ to partition the sequence $s$ into $\frac{1}{p}$ parts, such that each part contains $p\%$ number of elements of the whole sequence.

However, it becomes problematic for certain $n$ and $p$ combinations. For example, for $n=50$ and $p=5\%$, we are supposed to obtain 20 parts/sub-sequences. If we have $3$ elements per part, we will only have 17 of them while the last one contains only $2$ elements. If we have $2$ elements per part, we will have 20 of them but the last one will contain $12$ elements.

The purpose of partitioning the sequence in the first place is to calculate the mean for each resulting sub-sequence, i.e. that of first $p\%$, that of second $p\%$, and so on.

So what is a good way to deal with this situation?

-
For 50 only partition into multiples of 2%. – i. m. soloveichik Aug 30 '12 at 20:38
@i.m.soloveichik, $p$ is given and I have to use that. – MLister Aug 30 '12 at 20:44

Obviously you can't divide it up exactly in these cases, so you have to approximate. If you have a set of $n$ elements to be partitioned into $m$ subsets, you can write $n = mq + r$ where $q = \lfloor n/m \rfloor$ and $r \in \{0,1,\ldots,m-1\}$. You can then take $m-r$ subsets of size $q$ and $r$ subsets of size $q+1$.