tuple: Tuples

View source: R/tuple.R

tupleR Documentation

Tuples

Description

Creation and manipulation of tuples.

Usage

tuple(...)
as.tuple(x)
is.tuple(x)
singleton(...)
pair(...)
triple(...)
tuple_is_singleton(x)
tuple_is_pair(x)
tuple_is_triple(x)
tuple_is_ntuple(x, n)

Arguments

x

An R object.

n

A non-negative integer.

...

Possibly named R objects (for singleton, pair, and triple exactly one, two, and three, respectively.)

Details

These functions represent basic infrastructure for handling tuples of general (R) objects. Class tuple is used in particular to correctly handle cartesian products of sets. Although tuple objects should behave like “ordinary” vectors, some operations might yield unexpected results since tuple objects are in fact list objects internally. The Summary methods do work if defined for the set elements. The mean and median methods try to convert the object to a numeric vector before calling the default methods.

See Also

set.

Examples

## Constructor.
tuple(1,2,3, TRUE)
triple(1,2,3)
pair(Name = "David", Height = 185)
tuple_is_triple(triple(1,2,3))
tuple_is_ntuple(tuple(1,2,3,4), 4)

## Converter.
as.tuple(1:3)

## Operations.
c(tuple("a","b"), 1)
tuple(1,2,3) * tuple(2,3,4)
rep(tuple(1,2,3), 2)
min(tuple(1,2,3))
sum(tuple(1,2,3))

sets documentation built on May 29, 2024, 10:09 a.m.