R/create.ind.R

Defines functions create.ind

Documented in create.ind

#' Create Indicator Matrix
#' 
#' Create an indicator matrix.
#' 
#' @param grp A grouping vector.
#' @keywords utility
#' @export create.ind
create.ind <- function(grp) {
  K <- length(unique(grp))
  n <- length(grp)
  mat <- matrix(0, nrow = n, ncol = K)
  out <- apply(rbind(1:K, mat), 2, function(x, a) x[-1] + (a == x[1]), a = grp)
  out
}

Try the cds package in your browser

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

cds documentation built on May 2, 2019, 5:54 a.m.