for loop - R - Creating Probability of Occurrence in data frame -


If I want to make tables of 19 students, then each student has 10 figures that if they go to class on time Are there. I would like to randomize at 100% time rate, 90% at time rate, and 80% at each student time rate. I can not think of a way to make time per cent randomized for each person. (For example, the student is at the time rate of 90% at # 1, whereas the student is at the time rate of 70% in the # 2, etc.) That is the same if all students are at the rate of 90%, then come with it .

id & lt; -data.frame (Representative (1: 19, every = 10)) ID $ DOSE & lt; -c (copy (19, c (sample (rep (c ("timely

For every 19 students, Just draw a random timeline rate

  probs & lt; -k (.9, .8, .7) onTimeRates & lt; -sample (probs, 19, replace = TRUE) [1] 0.8 0.7 0.7 0.7 0.7 0.8 0.8 0.9 0.8 0.7 0.8 0.9 0.9 0.8 0.8 0.9 0.9 0.7 0.7  

Then get 10 data for each student, "on time" Related probabilities

  x <-> sapply (onTimeRates, function (x) sample  

Then this variable Change it to x

(c ('punctual', 'late'), 10, replace = TRUE, prob = c (x, 1- X) / code> in your desired column.

  ID $ DOSE & lt; -matrix (x, ncol = 1)  

Comments