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 |
how |
a |
centers |
(only relevant if |
... |
further arguments to be passed to or from other methods |
byrow |
|
ignore |
(only relevant if |
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")