some function

Sample a Few Elements of an Object

Sample a Few Elements of an Object

Randomly select a few elements of an object, typically a data frame, matrix, vector, or list. If the object is a data frame or a matrix, then rows are sampled.

some(x, ...) ## S3 method for class 'data.frame' some(x, n=10, cols=NULL, ...) ## S3 method for class 'matrix' some(x, n=10, cols=NULL, ...) ## Default S3 method: some(x, n=10, ...)

Arguments

  • x: the object to be sampled.
  • n: number of elements to sample.
  • cols: if NULL, use all columns, if a vector of column names or numbers, use only the columns indicated
  • ...: arguments passed down.

Returns

Sampled elements or rows.

Author(s)

John Fox jfox@mcmaster.ca

References

Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.

Note

These functions are adapted from head and tail

in the utils package.

See Also

head, tail, brief.

Examples

some(Duncan) some(Duncan, cols=names(Duncan)[1:3])