Skip to content

Instantly share code, notes, and snippets.

@slowkow
Created July 28, 2015 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slowkow/d81c070fa36e1b474d7e to your computer and use it in GitHub Desktop.
Save slowkow/d81c070fa36e1b474d7e to your computer and use it in GitHub Desktop.
Make a matrix indicating which samples are replicates.
#' Make a matrix suitable for use with RUVSeq methods such as RUVs().
#'
#' Each row in the returned matrix corresponds to a set of replicate samples.
#' The number of columns is the size of the largest set of replicates; rows for
#' smaller sets are padded with -1 values.
#'
#' @param xs A vector indicating membership in a group.
#' @seealso RUVSeq::RUVs
#' @example
#' makeGroups(c("A","B","B","C","C","D","D","D","A"))
#' [,1] [,2] [,3]
#' [1,] 1 9 -1
#' [2,] 2 3 -1
#' [3,] 4 5 -1
#' [4,] 6 7 8
makeGroups <- function(xs) {
xs <- factor(xs)
groups <- matrix(-1, nrow = length(levels(xs)), ncol = max(table(xs)))
for (i in 1:length(levels(xs))) {
idxs <- which(xs == levels(xs)[i])
groups[i,1:length(idxs)] <- idxs
}
groups
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment