Learn R Programming

gdata (version 2.2.0)

resample: Consistent Random Samples and Permutations

Description

resample takes a sample of the specified size from the elements of x using either with or without replacement.

Usage

resample(x, size, replace = FALSE, prob = NULL)

Arguments

x
A numeric, complex, character or logical vector from which to choose.
size
Non-negative integer giving the number of items to choose.
replace
Should sampling be with replacement?
prob
A vector of probability weights for obtaining the elements of the vector being sampled.

Value

  • ~Describe the value returned If it is a LIST, use
  • comp1Description of 'comp1'
  • comp2Description of 'comp2'
  • ...

Details

resample differs from the S/R sample function in resample always considers x to be a vector of elements to select from, while sample treats a vector of length one as a special case and samples from 1:x. Otherwise, the functions have identical behavior.

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

Run this code
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(x, n, ...)
  {
    if(length(x)==1)
      {
        if(n==1)
          x
        else
          stop("Requested sample of size ", n, "from list of length 1")
      }
    else
      sample(x, n, ...)
  }

Run the code above in your browser using DataLab