R/XtoS.R

XtoS <- function(X) {
  id.rows <- apply(X, 1, paste, sep = "", collapse = ".")
  id.rows
  Xtab <- table(id.rows)
  Xtab
  
  Xcat <- names(Xtab)
  Xcat
  
  S <- matrix(as.numeric(unlist(
    strsplit(Xcat, ".", fixed = TRUE))), 
    length(Xtab), ncol(X), byrow = TRUE)
  
  counts <- Xtab
  names(counts) <- NULL
  counts <- as.vector(counts)
  
  if(is.null(rownames(X))){
    rownames(X) <- paste("id", 1:nrow(X), sep = "_")
  }
  
  rownames(S) <- NULL
  
  out <- list(S = S, counts = counts, 
    idX = id.rows, idS = Xcat, Xnames = rownames(X))
  out
}

Try the lvm4net package in your browser

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

lvm4net documentation built on June 13, 2019, 5:03 p.m.