portion {portion}R Documentation

Extracting a data portion

Description

extract a portion of data saved as a vector, matrix, data.frame, or list

Usage

portion(x, proportion, how, centers = 2, ...)

## S3 method for class 'numeric'
portion(x, proportion, how, centers = 2, ...)

## S3 method for class 'matrix'
portion(x, proportion, how, centers = 2, byrow = TRUE, ignore = integer(), ...)

## S3 method for class 'data.frame'
portion(x, proportion, how, centers = 2, byrow = TRUE, ignore = integer(), ...)

## S3 method for class 'list'
portion(x, proportion, how, centers = 2, ...)

Arguments

x

an object to be portioned

proportion

a numeric between 0 and 1, the relative portion size

how

a character, specifying the portion method, one of: - "random" (default), portion at random - "first", portion to the first elements - "last", portion to the last elements - "similar", portion to similar elements based on clustering - "dissimilar", portion to dissimilar elements based on clustering

centers

(only relevant if how is "similar} or \code{"dissimilar)) an integer (default is 2), passed on to kmeans

...

further arguments to be passed to or from other methods

byrow

TRUE to portion row-wise (default) or FALSE to portion column-wise

ignore

(only relevant if how is "similar} or \code{"dissimilar)) an integer vector of row indices (or column indices if byrow = FALSE) to ignore during clustering

Value

the portioned input x with the (row, column) indices used added as attributes "indices"

Examples

# can portion vectors, matrices, data.frames, and lists of such types
portion(
  list(
    1:10,
    matrix(LETTERS[1:12], nrow = 3, ncol = 4),
    data.frame(a = 1:6, b = -6:-1)
  ),
  proportion = 0.5,
  how = "first"
)

# can portion similar elements
portion(c(rep(1, 5), rep(2, 5)), proportion = 0.5, how = "similar")

[Package portion version 0.1.0 Index]