Created
July 28, 2015 18:55
-
-
Save slowkow/d81c070fa36e1b474d7e to your computer and use it in GitHub Desktop.
Make a matrix indicating which samples are replicates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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