Displaying 2 results from an estimated 2 matches for "samplefrom".
2010 Nov 03
3
Using sample() to sample one value from a single value?
...e latter case 1.2 is coerced to an integer.
All of the above makes sense when one study the code of sample(), but
sample() is indeed dangerous, e.g. imagine how many bootstrap
estimates out there quietly gets incorrect.
In order to cover all cases of length(units), including one, a solution is:
sampleFrom <- function(x, size=length(x), ...) {
n <- length(x);
if (n == 1L) {
res <- x;
} else {
res <- sample(x, size=size, ...);
}
res;
} # sampleFrom()
> sampleFrom(rep(10, times=2), size=2);
[1] 10 10
> sampleFrom(rep(10, times=1), size=1);
[1] 10
> sampleFrom(r...
2010 Jun 28
2
sampling one random frame from each unique trial?
hello everyone. please bear with me if this is very easy...
I have a data set with many trials, and frames within each trial. I would
like to pull out one random frame from each trial.
here is an example. i have 4 unique trials (file), and various frames within
each (time_pred). I would like to randomly sample 4 rows, but 1 from each
trial (file).
this sample data is called "h"