Skip to content
Prev 165861 / 398502 Next

Randomly remove condition-selected rows from a matrix

Stavros Macrakis wrote:
interestingly, ?sample says:

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

       x: Either a (numeric, complex, character or logical) vector of
          more than one element from which to choose, or a positive
          integer.

    If 'x' has length 1, is numeric (in the sense of 'is.numeric') and
     'x >= 1', sampling takes place from '1:x'.  _Note_ that this
     convenience feature may lead to undesired behaviour when 'x' is of
     varying length 'sample(x)'.  See the 'resample()' example below.

"

yet the following works, even though x has length 1 and is *not* numeric:

x = "foolme"
is.numeric(x)
sample(x, 1)
sample(x)

x = NA
is.numeric(NA)
sample(x, 1)
sample(x)

is this a bug in the code, or a bug in the documentation?
hopefully.

vQ