Optimizing
Sam: 1. Homework? R has a no homework policy. 2. But in any case, check out the Optimization task view on CRAN. You should be able to find something there that meets your needs. Of course, if something is "a little over your head," that's not an excuse, but rather an admission that you have to do some "homework" on your own. Cheers, Bert
On Wed, Nov 14, 2012 at 5:23 PM, Sam Asin <asin.sam at gmail.com> wrote:
Hello,
I am fairly new with R and am having trouble finding an optimal group. I
checked the help functions for the various optimize commands and it was a
little over my head.
I have a dataset with 4 columns, name, type, value, and cost. The set
consists of a list of people, which have 3 types. I want to choose 6
people, two of each type, and maximize the sum of their values. However,
I'm subject to the constraint that the wage of the three people has to sum
to less than 20 dollars. Here is some sample data.
people <- c("A", "B", "C", "D", "E", "F", "G", "H", "I")
type<- c(1, 1, 1, 1, 2, 2, 3, 3, 3)
value<-c(25.20, 24, 38, 20, 14, 20, 31, 11, 8)
wage<- c(4, 3.8, 5.1, 3.5, 2.4, 3, 6, 2.4, 2)
data<- data.frame(people, type, value, wage)
With this small dataset the question isn't very interesting, but the answer
would be something like person C, D, E, F, G, and I (I didn't check to see
that those prices sum to less than $20).
How can I write a program that will do this? Can I just use the optimize
command? Do I have to transform my dataset into something that is easier
to use the optimize command on? Or should I write my own code that does
the process?
Thanks,
Sam
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm