toHistogram: Convert something to a histogram

View source: R/converters.R

toHistogramR Documentation

Convert something to a histogram

Description

The function tries to convert anything it gets to a histogram

Usage

toHistogram(X, breaks, ..., nsim = NULL, seed = NULL)

## S3 method for class 'numeric'
toHistogram(X, breaks, ..., nsim = NULL, seed = NULL)

## S3 method for class 'histogram'
toHistogram(X, breaks = NULL, ..., nsim = NULL, seed = NULL)

## S3 method for class 'BDataHistograms'
toHistogram(X, breaks, ..., nsim = NULL, seed = NULL)

## S3 method for class 'BDataUnivariateSamples'
toHistogram(X, breaks, ..., nsim = NULL, seed = NULL)

## S3 method for class 'BData'
toHistogram(X, breaks, ..., nsim = NULL, seed = NULL)

Arguments

X

the single data representing the histogram.

breaks

the breaks of the histogram. Most methods only work if given explicitly.

...

further arguments to the [graphics::hist] if called

nsim

number of datapoints to be simulated. If null, no simulation will take place.

seed

if not null the given seed will be used in case of a simulation and will be added as an attribute to the result (use with care).

Value

a histogram object, either with or without a counts element, depending on whether count data is availabel (e.g. through simulation.)

Methods (by class)

  • toHistogram(numeric): method computing the histogram from a sample

  • toHistogram(histogram): checks that the breaks fit and returns the histogram if they do.

  • toHistogram(BDataHistograms): checks that the breaks of the single histogram fit and returns the histogram if they do.

  • toHistogram(BDataUnivariateSamples): computes the histogram with the given breaks from the dataset.

  • toHistogram(BData): (not yet implemented) if nsim given, simulates a dataset from the distribution and computes a histogram from it, otherwise ...

See Also

Other BayesSpaceConverters: as.BDataDensities(), as.BDataDensityHistograms(), as.BDataFrequencyHistograms(), as.BDataHistograms(), as.BDataLogDensities(), as.BDataLogPDFs(), as.BDataPDFs(), as.BDataSamples(), as.BDataSplines(), idt.BData()

Examples

myBreaks = seq(0,1,by=0.2)
toHistogram(runif(100),breaks=myBreaks)
toHistogram(hist(runif(100),plot=FALSE,breaks=myBreaks),breaks=myBreaks)
toHistogram(BDataSamples(list(runif(100)),basis=B2Unif01Basis5),
            breaks=myBreaks)


DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.