brk2midp {lazy.tools}R Documentation

Define Midpoints from Break Points

Description

Define Midpoints from Break Points

Usage

brk2midp(brk, min = NULL)

Arguments

brk

a vector of break points.

min

The value of the lowest midpoint. This has priority over margin.

Details

Break values from midpoint values:
brk[1]=midp[1] - margin
brk[2]=midp[1] + (midp[2]-midp[1])/2
brk[3]=midp[2] + (midp[3]-midp[2])/2
brk[length(midpoints)+1]=midp[length(midpoints)] + margin
where margin=(midp[2]-midp[1])/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[1]=0.5*(brk[1]+brk[2]) or midp[1]=min
midp[2]=0.5*(brk[2]+brk[3])
midp[3]=2*brk[3]-midp[2]
brk[length(brk)-1]=2*brk[length(brk)-1]-midp[length(brk)-2]

Note that midp[1] 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 midpoints of length length(brk)-1.

Examples

midp <- c(0,1,2,4,6,9,10,11)
brk <- midp2brk( midp )
Print( midp, brk, brk2midp(brk) )
brk[1] <- -4
Print( midp, brk, brk2midp(brk) )


[Package lazy.tools version 0.1.3 Index]