inst/extdata/CodeLibrary/R/group.factor.R

#' Group a set of values into equally sized groups
#' 
#' Useful if wanting to group columsn like `ID` into groups
#' 
#' @param x vector to group
#' @param n group size
#' 
#' @export

group.factor <- function(x,n){
  GRP <- factor(x,levels=unique(x))
  levels(GRP) <- ((1:length(unique(x))-0.1) %/% n) + 1
  GRP
}

Try the NMproject package in your browser

Any scripts or data that you put into this service are public.

NMproject documentation built on Sept. 30, 2022, 1:06 a.m.