تمرین اول

mean(replicate(10000,sum(sample(0:1,3,repl=T))==2))

یا

mean(apply(matrix(sample(0:1,3*10000,repl=T),3),2,sum)==2)

تمرین دوم

mean(replicate(10000,abs(diff(runif(2,0,60)))<=10))

تمرین سوم

mprd=function(xx)

{

100 / length (xx) * sum ( abs ( (xx - mean(xx))/xx ) )

}

a=c(12,34,32,43,11,22) 

mprd(a)

تمرین چهارم

h=c(); for (i in 1:10000) {k=0; while(sample(1:6,1)<6) k=k+1; h=c(h,k)}; mean(h)