Learn R Programming

GMD (version 0.3.3)

ghist: Generalized Histogram Computation

Description

Generalized Histogram Computation with classes to contain a single histogram or multiple histograms

Usage

ghist(data,n,breaks=if (!.invalid(n)) NULL else "Sturges", bins=NULL,digits=1)
gbreaks(data, n)
is.ghist(x)
as.ghist(x,bins)
is.mhist(x)
as.mhist(x,bins)
mhist2matrix(h)

Arguments

data
a vector of values for which the histogram is desired.
n
a single number giving the number of bins for the histogram.
breaks
a vector giving the breakpoints between histogram bins, or a character string naming an algorithm to compute the number of bins, or a function to compute the number of bins (see help("dist", package="graphics")).
bins
character vecter, the bin labels.
digits
integer, the number of digits to round for breaks.
x
an R object.
h
an object of class mhist

Details

ghist generates a single histogram.

gbreaks generate bin boundaries for a histogram.

is.ghist returns TRUE if x is an object of codeghist and FALSE otherwise.

as.ghist is a generic function. The method for numeric vectors will return a ghist object.

is.mhist returns TRUE if x is an object of codemhist and FALSE otherwise.

as.mhist is a generic function. The method is for numeric list, matrices or data frames and will return a mhist object.

mhist2matrix convert a mhist object into a numeric matrix, filling observations by row.

See Also

plot.mhist mhist.summary plot.mhist.summary

Examples

Run this code
## load library
require("GMD")

## create two normally-distributed samples
## with unequal means and unequal variances
set.seed(2012)
v1 <- rnorm(1000,mean=-5, sd=10)
v2 <- rnorm(1000,mean=10, sd=5)

## create common bins
n <- 20 # desired number of bins
breaks <- gbreaks(c(v1,v2),n) # bin boundaries
x <-
  list(ghist(v1,breaks=breaks,digits=0),
       ghist(v2,breaks=breaks,digits=0))
mhist.obj <- as.mhist(x)

Run the code above in your browser using DataLab