0

I need build a dataframe with the results that I got in a for loop by the function polyroot. This function returns a list (as this is the only way that a function can return several values in R, correct?). I currently have this code that works:

for (i in p_hat) {
   positive <- append(positive, polyroot(parameters)[1])
   negative <- append(negative, polyroot(parameters))[1])
}
results <- data.frame(negative, positive)

My question is if is there anyway to directly, within the loop, construct the dataframe, I mean something like:

for (i in p_hat) {
    results[negative], results[positive] <- append(results, polyroot(parameters))
}

Thanks

  • Please consider providing us with a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that we can help you in the best possible way – lovalery Oct 14 '21 at 22:11

0 Answers0