I was working through the Rosetta Code example of the knapsack problem in R and I came up with four solutions. What is the best way to output only one of the solutions based on the observation number give in the table?
> values[values$value==max(values$value),]
I II III value weight volume
2067 9 0 11 54500 25 25
2119 6 5 11 54500 25 25
2171 3 10 11 54500 25 25
2223 0 15 11 54500 25 25
My initial idea was to save this output to a new variable, then query the new variable such as:
> newvariable <- values[values$value==max(values$value),]
> newvariable2 <- newvariable[2,]
> newvariable2
I II III value weight volume
2119 6 5 11 54500 25 25
This gives me the desired output but is there a cleaner way to do it?