Message-ID: <49874434.7080309@idi.ntnu.no>
Date: 2009-02-02T19:06:28Z
From: Wacek Kusnierczyk
Subject: New to R
In-Reply-To: <E3250543-A276-4962-8115-CEC954E067D0@earthlink.net>
Joe Hughes wrote:
>
> #
> function(die_size, number_of_dice, number_of_rolls)
> {
you may want to replace
> 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)
> }
with, e.g.
rolls = t(replicate(number_of_rolls, sample(die_size, number_of_dice,
replace=TRUE)))
to have it more r-ish
>
> return(rolls)
> }
>
> Any thoughts on this function?
as soon as you start wrapping something like subset, lm, or the like
inside your functions, all hell breaks loose. welcome to the r inferno,
that is.
vQ