To run a regresion by subset, I did as follows :
z1 <- sapply( split( data , data$code), function(d){ dat <- list2env(d) nlsfit <- nlsLM(form = SGP ~ a