[R] Simulation in R
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Aug 4 12:21:49 CEST 2013
On 04/08/2013 09:30, Rui Barradas wrote:
> Hello,
>
> See the help page for ?sample.
>
> X <- sample(0:1, 10000, replace = TRUE, prob = c(0.25, 0.75))
>
> Hope this helps,
?rbinom would have been a better answer since simpler, faster,
algorithms are available in that case.
Or even
as.integer(runif(10000) < 0.75)
> Rui Barradas
>
> Em 04-08-2013 08:51, Preetam Pal escreveu:
>> Hi All,
>>
>>
>> I want to simulate a random variable X which takes values 1 and 0 with
>> probabilities 75% and 25% respectively and then repeat the procedure
>> 10000
>> times.
>>
>> I am sure this is trivial, I tried to look at the help pages online,
>> but I
>> can't quite find it.
>>
>> Appreciate your help.
>>
>> Thanks and Regards,
>> Preetam
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list