[R] Simulating distribution of max of two die

S Ellison S.Ellison at LGCGroup.com
Tue Aug 30 12:33:48 CEST 2011


 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Jaap van Wyk
> Sent: 30 August 2011 04:57
> To: r-help at r-project.org
> Subject: [R] Simulating distribution of max of two die
>
>  how to find the distribution of the 
> maximum of rolling two balanced die. Is there perhaps a more 
> elegant way to do this, other than the way I am using below? 

#Perhaps
dice <- matrix(sample(1:6, 40000,replace=T), ncol=2)
dice.max <- apply(dice, 1, max)
barplot(table(dice.max)) 

#and just for interest
mids<-barplot(table(dice.max)/length(dice.max)) #gives proportions
all.pairs <- expand.grid(1:6, 1:6)
dice.max.exact <- apply(all.pairs, 1, max)

points(mids, table(dice.max.exact)/36, pch="_", cex=2, col=2)


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list