I have the the following data frame and variables:
u0 <- c(1,1,1,1,1)
df <- data.frame (u0)
a = .793
b = 2.426
r = 0.243
q = 1
w = 2
j = 1
z = .314
using the following loop I am doing some calculations and put the results in the first row of my data frame.
while (j<5){
df[q,w] <- df[q, w-1] * (r+j-1)*(b+j-1)*(z) / ((a+b+j-2)*j)
j = j + 1
w = w + 1
}
now I want to create another loop to do the same calculations for all rows (i.e I need the ‘q’ variable to vary) of my data frame. I would be thankful if anyone helps me.
You could either do this by putting your
whileloop inside of aforloop that goes overq, but a more R-tastic way would be to simply defineq <- 1:5, and leave the rest of your code as-is. Thendfwill fill up entirely. I take it in this example you want all rows to be identical?