Jessie Byrnes - 9 months ago 39

R Question

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

c=n1(n1-R_1-1)(n1-R_1-R_2-2)...(n1-R_1-R_2-...-R_{m1-1}-m1+1)

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

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)}
}
```

Source (Stackoverflow)