This function receveis a factor and return a numeric vector with equally spaced factor levels centered at 0.

centfac(group, space = NULL)

Arguments

group

A factor.

space

A numeric value to be used as the space between levels. If NULL, the space is determined by the group.

Examples

centfac(warpbreaks$tension)
#> [1] -0.1666667 -0.1666667 -0.1666667 -0.1666667 -0.1666667 -0.1666667 #> [7] -0.1666667 -0.1666667 -0.1666667 0.0000000 0.0000000 0.0000000 #> [13] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 #> [19] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 #> [25] 0.1666667 0.1666667 0.1666667 -0.1666667 -0.1666667 -0.1666667 #> [31] -0.1666667 -0.1666667 -0.1666667 -0.1666667 -0.1666667 -0.1666667 #> [37] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 #> [43] 0.0000000 0.0000000 0.0000000 0.1666667 0.1666667 0.1666667 #> [49] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667
centfac(warpbreaks$tension, space = 1)
#> [1] -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 #> [26] 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 #> [51] 1 1 1 1
centfac(warpbreaks$wool)
#> [1] -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 #> [13] -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 #> [25] -0.25 -0.25 -0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 #> [37] 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 #> [49] 0.25 0.25 0.25 0.25 0.25 0.25
centfac(warpbreaks$wool, space = 1)
#> [1] -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 #> [26] -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 #> [51] 1 1 1 1