[R] Sample function in R

Petr Savicky savicky at cs.cas.cz
Sun Feb 12 20:29:18 CET 2012


On Sun, Feb 12, 2012 at 01:57:18PM -0500, SUPAKORN LAOHAPITAKVORN wrote:
> This is what I got:
> 
> > sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
> 
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> > ls()
> [1] "a"      "sample"

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.



More information about the R-help mailing list