2011/9/6 Jean-Christophe BOUËTTÉ :
you could tapply
function(x) if(length(x)==1) x else sample(x)
or something like this
>
> 2011/9/6 Jean-Christophe BOUËTTÉ :
>> Hi there,
>> in the third case you get sample(5) which is exactly what you asked for.
>>
>> from ?sample:
>> "If x has length 1, is nu
Hi there,
in the third case you get sample(5) which is exactly what you asked for.
from ?sample:
"If x has length 1, is numeric (in the sense of is.numeric) and x >=
1, sampling via sample takes place from 1:x. Note that this
convenience feature may lead to undesired behaviour when x is of
varying
On 11-09-06 8:13 PM, Jack Siegrist wrote:
I want to sample within groups, and when a group has only one associated
number to just return that number.
If I use this code:
groups<- c(1, 2, 2, 2, 3)
numbers<- 1:5
tapply(numbers, groups, FUN = sample)
I get the following output:
groups<- c(1,
On Sep 6, 2011, at 8:13 PM, Jack Siegrist wrote:
I want to sample within groups, and when a group has only one
associated
number to just return that number.
And what we supposed to do when it has more than one value?
If I use this code:
groups <- c(1, 2, 2, 2, 3)
numbers <- 1:5
tapp
I want to sample within groups, and when a group has only one associated
number to just return that number.
If I use this code:
groups <- c(1, 2, 2, 2, 3)
numbers <- 1:5
tapply(numbers, groups, FUN = sample)
I get the following output:
> groups <- c(1, 2, 2, 2, 3)
> numbers <- 1:5
> tapply(
5 matches
Mail list logo