R/dummy.R

Defines functions dummy

Documented in dummy

dummy <- function(f,simplify=TRUE) {
  f <- droplevels(factor(f))
  mat <- I(model.matrix(~x-1,data=data.frame(x=f)))
  if (simplify) {
    res <- as.matrix(mat[,-ncol(mat)],nrow=length(f))
    colnames(res) <- levels(f)[-nlevels(f)]
  } else {
    res <- as.matrix(mat[,1:ncol(mat)],nrow=length(f))
    colnames(res) <- levels(f)
  }
  return(res)
}

Try the RVAideMemoire package in your browser

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

RVAideMemoire documentation built on Nov. 6, 2023, 5:07 p.m.