Learn R Programming

DescTools (version 0.99.43)

Some: Return Some Randomly Chosen Elements of an Object

Description

For displaying the first and last elements of an object there are the functions head and tail. Sometimes one might want to see more randomly scattered elements. This function returns some random parts of a vector, matrix or a data frame. The order of the elements within the object will be preserved.

Usage

Some(x, n = 6L, …)
# S3 method for default
Some(x, n = 6L, …)
# S3 method for data.frame
Some(x, n = 6L, …)
# S3 method for matrix
Some(x, n = 6L, addrownums = TRUE, …)

Arguments

x

an object

n

a single integer. If positive, size for the resulting object: number of elements for a vector (including lists), rows for a matrix or data frame or lines for a function. If negative, all but the n last/first number of elements of x.

addrownums

if there are no row names, create them from the row numbers.

arguments to be passed to or from other methods.

Value

An object (usually) like x but generally smaller.

Details

For matrices, 2-dim tables and data frames, Some() returns some n rows when n > 0 or all but the some n rows when n < 0. Some.matrix() is not exported (unlike head.matrix).

If a matrix has no row names, then Some() will add row names of the form "[n,]" to the result, so that it looks similar to the last lines of x when printed. Setting addrownums = FALSE suppresses this behaviour.

I desisted from implementing interfaces for tables, ftables and functions, as this would not make much sense.

See Also

head

Examples

Run this code
# NOT RUN {
Some(letters)
Some(letters, n = -6L)

Some(freeny.x, n = 10L)
Some(freeny.y)
# }

Run the code above in your browser using DataLab