Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Joe Hughes
> Sent: Monday, February 02, 2009 1:09 PM
> To: R help
> Subject: Re: [R] New to R
>
> All,
>
> Thanks for taking the time to reply. I understand a bit more
> about R
> and the R way then I did before. The final function looks like this:
>
> #######################################################################
> #######
> #
> # Input:
> # die_size - 4, 6, 8, 10, 20
> # number_of_dice - How many dice to roll
> # number_of_rolls - How many times to roll the dice
> #
> # Output:
> # The array holding the results of the rolls
> #
> #######################################################################
> #######
> #
> function(die_size, number_of_dice, number_of_rolls=1)
> {
> return(t(replicate(number_of_rolls, sample(die_size,
> number_of_dice,
> replace=TRUE))))
> }
>
> Before I take a look at the teaching demos, I have one question left.
>
> Here is a sequence of commands and the output
>
> > sample(6, 4, replace=TRUE)
> [1] 3 4 5 4
> > replicate(7, sample(6, 4, replace=TRUE))
> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> [1,] 3 3 6 4 5 6 6
> [2,] 4 4 6 5 5 1 6
> [3,] 5 1 4 5 6 5 6
> [4,] 4 6 3 1 1 2 2
>
> Why does replicate transpose the vector before assigning it to the
> array? The way I would output it would be this
>
> [,1] [,2] [,3] [,4]
> [1,] 3 4 5 4
> [2,] 3 4 1 6
> [3,] 6 6 4 3
> [4,] 4 5 5 1
> [5,] 5 5 6 1
> [6,] 6 1 5 2
> [7,] 6 6 6 2
>
> Thanks,
> Joe
>
> ______________________________________________
> R-help at 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.