Performing machine learning
You can avoid appending to vectors (which can cause re-allocation of space and can considerably slow things down in principle; though in your case of only a length 10 vector that shouldn't be noticeable) if you allocate them to the needed size initially and then assign within them.

result &lt;- vector("numeric", 10)
# or even: result &lt;- numeric(10)
n &lt;- vector("numeric", 10)

for (i in 2:10)
{
  avg &lt;- kf.nnet(data, 5, i)
  result[i] &lt;- avg
  n[i] &lt;- i
  cat("!!!!!!!", i, avg, "\n")
}


I'm not clear what you are asking about combing function; you can add an additional argument which is a character vector which then the code just has a series of if/elseif's checking that parameter to see which algorithm to use, if that is what you mean.