The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Type: Package
Title: Extracting a Data Portion
Version: 0.1.2
Description: Provides simple methods to extract data portions from various objects. The relative portion size and the way the portion is selected can be chosen.
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
Imports: stats
URL: https://github.com/loelschlaeger/portion
BugReports: https://github.com/loelschlaeger/portion/issues
NeedsCompilation: no
Packaged: 2025-06-10 16:29:13 UTC; Lennart Oelschläger
Author: Lennart Oelschläger [aut, cre]
Maintainer: Lennart Oelschläger <oelschlaeger.lennart@gmail.com>
Repository: CRAN
Date/Publication: 2025-06-10 16:40:02 UTC

portion: Extracting a Data Portion

Description

logo

Provides simple methods to extract data portions from various objects. The relative portion size and the way the portion is selected can be chosen.

Author(s)

Maintainer: Lennart Oelschläger oelschlaeger.lennart@gmail.com

See Also

Useful links:


Extracting a data portion

Description

Methods to extract portions of different objects.

Usage

portion(x, proportion, how = "random", centers = 2L, ...)

## Default S3 method:
portion(x, ...)

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

## S3 method for class 'character'
portion(x, proportion, how = "random", ...)

## S3 method for class 'logical'
portion(x, proportion, how = "random", centers = 2L, ...)

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

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

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

Arguments

x

An object to be portioned.

proportion

[numeric(1)]
The relative portion size between 0 and 1 (rounded up).

how

[character(1)]
Specifying how to portion, one of:

  • "random" (default), portion at random

  • "first", portion to the first elements.

  • "last", portion to the last elements

  • "similar", portion to similar elements

  • "dissimilar", portion to dissimilar elements

Options "similar" and "dissimilar" are based on clustering via kmeans and hence are only available for numeric x.

centers

[integer(1)]
Only relevant if how = "similar" or how = "dissimilar".

In this case, passed on to kmeans for clustering.

...

Further arguments to be passed to or from other methods.

byrow

[logical(1)]
Only relevant if x has two dimensions (rows and columns).

In this case, set to TRUE to portion row-wise (default) or FALSE to portion column-wise.

ignore

[integer()]
Only relevant if how = "similar" or ⁠how = "dissimilar⁠.

In this case, row indices (or column indices if byrow = FALSE) to ignore during clustering.

Value

The portioned input x with selected (row, column) indices 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 and dissimilar elements (based on kmeans clustering)
x <- c(1, 1, 2, 2)
portion(x, proportion = 0.5, how = "similar")
portion(x, proportion = 0.5, how = "dissimilar")

# object attributes are preserved
x <- structure(1:10, "test_attribute" = "test")
x[1:5]
portion(x, proportion = 0.5, how = "first")

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.