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 29, 2017, 6:52 p.m.