midp2brk {lazy.tools} R Documentation

## Define Break Points from Midpoints

### Description

Define Break Points from Midpoints

### Usage

```midp2brk(midpoints, min = NULL, max = NULL, margin = NULL)
```

### Arguments

 `midpoints` a vector of midpoints. `min` value of the lowest break. `max` value of the highest break. `margin` value to be subtracted/added to the lowest and highest midpoints. default margin = ( midpoints-midpoints )/2

### Details

Break values from midpoint values:
`brk=midp - margin`
`brk=midp + (midp-midp)/2`
`brk=midp + (midp-midp)/2`
`brk[length(midpoints)+1]=midp[length(midpoints)] + margin`
where `margin=(midp-midp)/2`.
In general, the break point is located at the center of two midpoints:
`brk[k]=0.5*(midp[k-1]+midp[k])`

Midpoint values from break values:
`midp=0.5*(brk+brk)` or midp=min
`midp=0.5*(brk+brk)`
`midp=2*brk-midp`
`brk[length(brk)-1]=2*brk[length(brk)-1]-midp[length(brk)-2]`

Note that midp is treated separately and it is assumed that the break point is located at the center of two midpoints.

Try below to see how the obs on the border are classified.
` xx <- c(1,2,3,4,5,6,7) `
` brks <- c(0,2,4,6,8) `
` cc1 <- cut(xx,brks) `
` cc2 <- cut(xx,brks, right=FALSE) `
` Print(xx,as.character(cc1),as.character(cc2)) `

### Value

A vector of break points of length length(midpoints)+1.

### Examples

```midp <- seq(0,5,length.out=11)
brk <- midp2brk( midp, margin=1 )
Print(midp,brk)

midp <- seq(0,5,length.out=11)
brk <- midp2brk( midp, margin=1 )
Print(midp,brk)

set.seed(1701)
x <- rnorm(100)+2.5

# histogram by native hist
resh <- hist( x, breaks=brk )

# histogram by native barplot
# freq <- resh\$counts
# names(freq) <- midp
# barplot( freq, space=0 )
barplot( resh\$count,names.arg=midp, space=0, xlab="X", col="white"
, sub="top and bottom bars contain outliers." )

# Below causes error because 'brk' does not span the range of 'x'.
# brk <- midp2brk( midp )
# resh <- hist( x, breaks=brk )

```

[Package lazy.tools version 0.1.3 Index]