Transform data to have specific mean, minimum and maximum? I have found this in regards to transforming to specific mean and maximum, but I need to specify a minimum as well. Is there a way to do so?
I believe it will be a more complicated solution similar to what's proposed here, but I haven't found in this second link a solution to what I need.
Thanks in advance!
 A: There are many different transformations that could work for this (probably infinite), but here is a fairly simple one that works for the median instead of the mean (thanks @Glen_b for catching the mistake):


*

*Subtract the current median from all data points (now the median will be 0).

*Divide all the positive values by the current max, then multiply them by the difference between the desired max and the desired median.

*Divide all the negative values by the absolute value of the current min, then multiply them by the difference between the desired median and the desired min.

*Add the desired median to all points.


Now the data will have the desired min, max, and median.
If the ratio of the differences between the extremes and the mean and the desired extremes are close then this will be close as well, otherwise some additional shifting will be needed.
Another approach for the mean (that keeps the order of the points):


*

*Subtract the minimum value from all values and divide all the new values by the new max (now the values will all be between 0 and 1).

*Raise all the values to the same power ($x^p$), finding the correct value of $p$ will be the tricky part, but you could use trial and error or an optimization or root finding function.  

*Multiply by the difference between the desired max and min, then add the min.


The dataset will need to have at least 3 unique values for this (or anything that retains the order) to work.
Edit
Here is some example R code that uses the second option (tested this time to make sure that it works):
scaleMMM <- function(x, min.target=-1, max.target=1, mean.target=0,
                     p.range=c(0.01,10)) {
  tmpfun <- function(p) {
    x2 <- x-min(x)
    x2 <- x2/max(x2)
    x2 <- x2^p
    x2 <- x2*(max.target-min.target) + min.target
    x2
  }

  p <- uniroot(function(p){mean(tmpfun(p))-mean.target}, p.range)$root

  out <- tmpfun(p)
  attr(out, 'p') <- p
  out
}


x1 <- rexp(25)
summary(x1)
x2 <- scaleMMM(x1)
summary(x2)

plot(x1,x2)

A: This explains how to get Greg's original idea for rescaling positive and negative parts each in a linear way to give the desired outcome.
Let $P = (P_1,P_2,...,P_n)'$, and $N = (N_1,N_2,...,N_m)'$, 
where the elements of $P$ and $N$ are all non-negative.
Let $\bar{P}$ and $\bar{N}$ be the mean of the vectors $P$ and $N$
respectively
Consider a set of data with both positive and negative elements (as might be obtained by mean-correcting or median-correcting an existing set of data), where $X=(-N,P)'$. 
Now let $Y = (-aN,bP)+c$ for $a,b>0$. 
Then $\min(Y)=-aN_{(m)}+c$, $\max(Y)=bP_{(n)}+c$ and $\bar{Y}=(nb\bar{P}-ma\bar{N})/(m+n)+c$.
To obtain a desired min, max and mean for $Y$, simply solve the above three (linear) equations for $a,b,c$
If $\min(Y)=l,\max(Y)=u$ and $\bar{Y}=d$ then we solve
\begin{eqnarray}
-aN_{(m)} + c &=& l\\
bP_{n}+c &=&u\\
(nb\bar{P}-ma\bar{N})/(m+n)+c&=&d
\end{eqnarray}
for $a,b,c$. 
Let $v = (a,b,c)'$ and let $z=(l,u,d)'$. In matrix form we are trying to solve:
$$Av = z$$ 
where  
$$A= 
    \begin{bmatrix}
    -N_{(m)} & 0 & 1 \\
    0 & P_{(n)} & 1 \\
    -\frac{m}{m+n}\bar{N} & \frac{n}{m+n}\bar{P} & 1 \\
    \end{bmatrix}\,.
$$
with a few more lines of algebra we could write an explicit solution, but I'll have to come back to that later. As it is, this is straightforward to implement as is in many programs, since solving linear systems is easy, it would be a simple matter to write a few lines of code to get the scale factors $a,b$ and $c$.
