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