From retep.meissner at gmail.com  Tue Jun 16 13:32:18 2015
From: retep.meissner at gmail.com (Peter Meissner)
Date: Tue, 16 Jun 2015 13:32:18 +0200
Subject: [Rd] Add-on argument in sample()
In-Reply-To: <D62EEDC839E38446B9F9378AFA4408E983EEA95E@mbxparis01.recherche.curie.fr>
References: <D62EEDC839E38446B9F9378AFA4408E983EEA95E@mbxparis01.recherche.curie.fr>
Message-ID: <op.x0bmb4ju3euttn@zukd208>

Am .06.2015, 14:55 Uhr, schrieb Millot Gael <Gael.Millot at curie.fr>:

> Hi.
>
> I have a problem with the default behavior of sample(), which performs  
> sample(1:x) when x is a single value.
> This behavior is well explained in ?sample.
> However, this behavior is annoying when the number of value is not  
> predictable. Would it be possible to add an argument
> that desactivates this and perform the sampling on a single value ?  
> Examples:
>> sample(10, size = 1, replace = FALSE)
> 10
>
>> sample(10, size = 3, replace = TRUE)
> 10 10 10
>
>> sample(10, size = 3, replace = FALSE)
> Error

I think the problem here is that the function actually does what you would  
expect it to do given a statistic perspective. A sample of size three from  
a population of one without allowing to draw elements again that were  
drawn already is simply not defined. What shall the function give back?

... You can always wrap your code in a try() like this to prevent errors  
to break loops or functions:

try(sample(...))

... or you might check your arguments before execution:


if ( !replace & length(population) >= size ){
   sample(population, size = size , replace = replace)
}else{
   ...
}


>
> Many thanks for your help.
>
> Best wishes,
>
> Gael Millot.
>
>
> Gael Millot
> UMR 3244 (IC-CNRS-UPMC) et Universite Pierre et Marie Curie
> Equipe Recombinaison et instabilite genetique
> Pav Trouillet Rossignol 5eme etage
> Institut Curie
> 26 rue d'Ulm
> 75248 Paris Cedex 05
> FRANCE
> tel : 33 1 56 24 66 34
> fax : 33 1 56 24 66 44
> Email : gael.millot at curie.fr
> http://perso.curie.fr/Gael.Millot/index.html
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


Best, Peter

--



[Rd] Add-on argument in sample()
Peter Meissner