R/i.dummy.R

dummy <- function (v){ #dummy coding with NA
  t <- table(v)
  lt <- length(t)
  n.obs <- length(v)
  new <- matrix(NA, nrow = n.obs, ncol = lt)
  vv <- as.numeric(as.factor(v))
  for (i in 1:n.obs) {
    new[i, vv[i]] <- 1
    new[i, -vv[i]] <- 0
  }
  colnames(new) <- names(t)
  new
  return(new)
}

Try the pairwise package in your browser

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

pairwise documentation built on April 18, 2023, 1:10 a.m.