Skip to content
Prev 208091 / 398502 Next

How to choose a number subset with sum closest to x?

I am looking for a function that, when supplied a vector of floats x,  an
integer n, and float s, would find me an n-subset of x with the sum closest
to s. Can anyone point me to a package/function that can do the job - better
yet, provide a relevant code sample? (There are a few relevant packages on
CRAN, but lack of examples in their docs is a real problem).

Thank you.