Extract: Extract or replace parts of a hyper2 object

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Extract or replace parts of a hyper2 object

Usage

1
2
3
4
## S3 method for class 'hyper2'
x[...]
## S3 replacement method for class 'hyper2'
x[index, ...] <- value

Arguments

x

An object of class hyper2

...

Further arguments, currently ignored

index

A list with integer vector elements corresponding to the brackets whose power is to be replaced

value

Numeric vector of powers

Details

These methods should work as expected, although the off-by-one issue might be a gotcha.

For the extract method, a numeric vector is returned but the elements may be in any order (the brackets and indeed the powers are not stored in any particular order).

The replace method, a[L] <- value, the index L is a list specifying the brackets to be overwritten; argument value is not recycled unless it is of length 1.

If the index argument is missing, viz a[] <- b, this is a special case. Argument b must be a hyper2 object, and the idiom effectively executes a[brackets(b)] <- powers(b), but more efficiently. This special case is included in the package because it has a very natural C++ expression [function overwrite() in the src/ directory] that was too neat to omit.

Value

The extractor method returns a hyper2 object, restricted to the elements specified

Note

Use powers() and brackets() to extract a numeric vector of powers or a list of integer vectors respectively.

Replacement idiom A[x] <- val cannot use non-trivial recycling. This is because the elements of a are not stored in a system-dependent order.

Author(s)

Robin K. S. Hankin

See Also

hyper2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data(chess)

chess[1]
chess[c(1,2)]
chess[list(1,1:2)]
chess[1] <- 5

a <- hyper2(pnames=letters[1:8])
a[sapply(seq_len(8),seq_len)] <- 1
a

b <- a
b[1] <- 1000
b[2] <- 2000
b[] <- a      # b[1] overwritten; b[2] preserved

hyper2 documentation built on July 6, 2017, 9:02 a.m.