Jessie Byrnes Jessie Byrnes - 10 months ago 45
R Question

R - Expanding Product Based on Previous Result

I am relatively new to R and am trying to write a code for:


I essentially want to create a vector containing all possible values of c. Note that n1 and m1 are fixed values.

Here is my attempt:

c[j]<- for (j in 1:m1)
if (c==1) {n}
else (c>1) {n(n-R_1-1)}

I know this is wrong. I am struggling with the structure. Any help would be much appreciated. Thanks.

Answer Source

I'm still unsure about what you are asking. But does this solve the issue?

    m1 = 8
    n = 6
    c <- numeric(m1)
    R_1 <- 3

    for (j in 1:m1){
      if (j==1) {c[j] <- n}
      else {c[j]<- c[j-1]*(c[j-1]-R_1-1)}