Skip to content

Sample function in R

6 messages · R. Michael Weylandt, Jorge I Velez, SUPAKORN LAOHAPITAKVORN +2 more

#
sessionInfo()?

Can you replicate this behavior in a R --vanilla session? This seems
very odd and I presume you've overwritten sample() somewhere in your
workspace.

Michael

On Sun, Feb 12, 2012 at 12:52 PM, SUPAKORN LAOHAPITAKVORN
<klangklang2002 at gmail.com> wrote:
#
On Sun, Feb 12, 2012 at 01:57:18PM -0500, SUPAKORN LAOHAPITAKVORN wrote:
Hi.

The standard R base function sample() is not shown
by ls() command. So, the above is something different
as others already suggested. You can see, what it
is, by typing "sample" without quotation marks and
without (). The standard sample prints as the following

  > sample
  function (x, size, replace = FALSE, prob = NULL) 
  {
      if (length(x) == 1L && is.numeric(x) && x >= 1) {
          if (missing(size)) 
              size <- x
          .Internal(sample(x, size, replace, prob))
      }
      else {
          if (missing(size)) 
              size <- length(x)
          x[.Internal(sample(length(x), size, replace, prob))]
      }
  }
  <environment: namespace:base>

Start new session or delete the wrong sample by rm(sample).
If it comes from a script, which you run, the situation
may repeat. In this case, look into the scripts for
commands like "sample <- ...".

Hope this helps.

Petr Savicky.