Carrie Li wrote:
Dear R-helpers,
I would like to generate a variable that takes 0 or 1, and each subject has
different probabilities of taking the draw.
So, which of the following code I should use ?
<snip>
I don't think either.
Try this:
probs <- seq(0,1, by = .1)
sapply(probs, function(x) sample(0:1, 1, prob = c(1-x, x)))
probs will be the vector of your probabilities for obtaining a '1' per subject,
so set that to whatever you want, then run the second line.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.