R/as.binaryMatrix.R

Defines functions as.binaryMatrix

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
###
### as.matrix.kstructure.R
###
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
###
### dependencies: library(sets)
###
### 2018-04-13: created
###


as.binaryMatrix <- function(x) {

   ### check x
  if (!inherits(x, "set")) {
    stop(sprintf("%s must be of class %s.", dQuote("x"), dQuote("set")))
  }

  states <- lapply(x, as.character)
  items <- sort(unique(unlist(states)))
  R <- matrix(0, length(x), length(items),
              dimnames=list(NULL, items))
  for (i in seq_len(nrow(R))) R[i, states[[i]]] <- 1
  storage.mode(R) <- "integer"
  class(R) <- unique(c("kmfamset", class(R)))
  R
}

Try the kstIO package in your browser

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

kstIO documentation built on March 8, 2026, 5:06 p.m.