Scaling a series of numbers Suppose I have 30 numbers that vary between 0 and 1.0 and which sum to 1.0.  The mean is obviously 0.033.  A client wants these scaled to lie between 0 and 1.0 but to have a mean of 0.5.  By the way, I'll probably have to do this for any set of numbers (positive, negative, outside the range 0 - 1) so that they lie in the range 0 - 1 and have a mean 0.5.  Any suggestions?
 A: What about ranking the data, subtracting 1, and dividing by $N-1$? Values range from 0 to 1, and have a mean of 0.5?
$$\mathbf{X^{*}} = \frac{\text{rank}[\text{sort}(\mathbf{X})]-1}{N-1}$$
In R:
# fun: given a vector of reals, returns corresponding scores from 0 to 5, w/ mean =0.5
fun <- function(x) {
  return((rank(sort(x))-1)/(length(x)-1))
  }

A: A simple approach using only basic arithmetical operations is a two-step calculation as follows, where the original numbers are $X_i(i = 1,…,n)$ and their mean is $M$:
First, adjust the numbers to set the mean to 0.5 while preserving their absolute differences.  To achieve this, replace each $X_i$ by $X_i’$ where:
$$X_i’ = X_i + (0.5 – M)$$
The new mean will be 0.5 since:
$$∑X_i' / n  =  ∑(X_i + (0.5 – M)) / n  =  M + 0.5 – M  =  0.5$$
Then adjust the numbers from the first step to narrow their spread around 0.5 so that they all lie within the range 0 – 1, while preserving the mean as 0.5.  To achieve this,  select a suitable positive constant $k$ and replace each $X_i’$ by $X_i^*$, where:
$$X_i^* = 0.5 + k(X_i’ – 0.5)$$
This preserves the mean as 0.5 since:
$$∑X_i^* / n  =  ∑(0.5 + k(X_i’ – 0.5)) / n  =  0.5 + k(0.5 – 0.5)  =  0.5$$
To find a suitable value of $k$, find the $X_i'$ which differs most from 0.5, say $X_a’$, and choose $k$ so as to scale $|X_a’– 0.5|$ down to no more than 0.5.  Thus $k$ must satisfy:
$$0 < k ≤ 0.5 / (\max(|X_i’ – 0.5|))$$
This excludes $k = 0$, on the assumption that a scaling leading to all the numbers being 0.5 is not wanted. 
