CrisGuN
CrisGuN

Reputation: 19

Creating n columns to a dataframe

I'm trying to create multiple columns with a for loop to simulate different kinds of scenarios.

The code I'm thinking of is like

X=10    #number of iterations
P=2/14  #Probability of success
n=14    #Nummber of iterations

for (i in 1:X){

P=(qbinom(runif(1), n, P))/n # Random Binomial Probability

Results["i"]=P #I don't know how to do this bit

}

the Results["i"]=P bit is the part I don't know how to do, for each iteration I need X columns showing in each one the result of the random experiment

Thanks

Upvotes: 0

Views: 252

Answers (1)

BoyInDaBox89
BoyInDaBox89

Reputation: 417

here is the help:

declear:

results <- NULL

and inside the for loop:

results <- cbind(results,P) #keep in mind length of P should be same.

Upvotes: 1

Related Questions