I created a loop to calculate the following formula: values = 1+PE - (1+(i^w))^(1/w)) where PE and w change as follows:
#creation of my variables
w <- seq(1, 4, by = 0.1)
PE <- seq(1, 2, by = 0.1)
#creation of a matrix where I will be storing the results of the loop
results <- matrix(nrow= length(PE) , ncol= length(w))
#loop where w and PE are changing
for(i in PE){
for (j in w){
results <- (1+i - (1+(i^j))^(1/j))
print (results)
}
}
results
If I run it I obtain a list where all my values are printed, but I face 2 problems:
i) I cannot store those values. When I print results outside the loop, I obtain 1 value and not all of them. So i cannot manipulate them to create a matrix and neither a data frame.
ii) I initially created a matrix for those values to be stored so when I add in the loop: results[i, j] I get several matrices with many NA values when I should be getting only one matrix. And this matrix should have 11 rows and 31 columns