It sounds like lsqnonlin
in the pracma
package is what you're looking for.
I recommend installing the sos
package for R. Its purpose is to help you answer questions like 'Is there a function out there that does this?'. findFn
in this package will search what's on CRAN for the term you supply.
library(sos)
findFn('lsqnonlin')