sub-.Arrdist: Extract one or more Distributions from an Array distribution

[.ArrdistR Documentation

Extract one or more Distributions from an Array distribution

Description

Extract a WeightedDiscrete or Matdist or Arrdist from a Arrdist.

Usage

## S3 method for class 'Arrdist'
ad[i = NULL, j = NULL]

Arguments

ad

Arrdist from which to extract Distributions.

i

indices specifying distributions (first dimension) to extract, all returned if NULL.

j

indices specifying curves (third dimension) to extract, all returned if NULL.

Value

If length(i) == 1 and length(j) == 1 then returns a WeightedDiscrete otherwise if j is NULL returns an Arrdist. If length(i) is greater than 1 or NULL returns a Matdist if length(j) == 1.

Examples

pdf <- runif(400)
arr <- array(pdf, c(20, 10, 2), list(NULL, sort(sample(1:20, 10)), NULL))
arr <- aperm(apply(arr, c(1, 3), function(x) x / sum(x)), c(2, 1, 3))
darr <- as.Distribution(arr, fun = "pdf")
# WeightDisc
darr[1, 1]
# Matdist
darr[1:2, 1]
# Arrdist
darr[1:3, 1:2]
darr[1, 1:2]

alan-turing-institute/distr6 documentation built on Feb. 26, 2024, 11 a.m.