Gabor,
Shouldn't the replace be TRUE instead of FALSE? I get this error
Error in sample(6, 28, replace = FALSE) :
cannot take a sample larger than the population when 'replace =
FALSE'
when I use FALSE. I don't get the error when it is TRUE. Examining
my mental model of what is going on you can't remove a number from a
die thus each sample(value of the die) when selected has to be
replaced. Or am I missing something?
Thanks,
Joe
On Feb 2, 2009, at 1:00 PM, Gabor Grothendieck wrote:
Try this:
matrix(sample(dsize, nrolls * ndice, replace = FALSE), nrolls, ndice)
On Mon, Feb 2, 2009 at 12:39 PM, Joe Hughes
<joe.hug...@earthlink.net> wrote:
Hello All,
A colleague of mine started working with R and out of
curiosity I did
some research on the language. Very nice. In my opinion this is
one of the
best languages I've found for getting tasks I'm interested in
done. I wrote
this simple die roller and was curious to know if it is R enough.
##############################################################################
#
# 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:
# rolls - The array holding the values of the dice
#
##############################################################################
#
function(die_size, number_of_dice, number_of_rolls)
{
rolls <- array(0, dim=c(number_of_rolls, number_of_dice))
for (i in 1:number_of_rolls)
{
rolls[i,] <- sample(die_size, number_of_dice,
replace=TRUE)
}
return(rolls)
}
Any thoughts on this function? Is there a better way of doing it
in R? Can
you tell I used to play AD&D?
Thanks,
Joe
______________________________________________
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.
______________________________________________
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.