inst/rsp-ex/TCGA,CMTN/R/getBalancedRegions.R

##############################################################
# sample data to get the same number of points in each state
##############################################################
setMethodS3("getBalancedRegions", "SegmentedGenomicSignalsInterface", function(this, minNbP=NULL, ..., verbose=FALSE) {
  if (is.null(minNbP)) {
    states <- getStates(this);
    minNbP <- table(states);
  }

  res <- NULL;
  states <- getUniqueStates(this);
  # Sanity check
  for (ss in seq_along(states)) {
    state <- states[ss];
    thisByState <- extractSubsetByState(this, state);
    nbUnits <- length(thisByState$y);
    if (!is.na(state)) {
      subset <- sample(nbUnits, minNbP, ...);
      thisByState <- extractSubset(thisByState, subset);
    }
    if (is.null(res)) {
      res <- thisByState;
    } else {
      append(res, thisByState);
    }
  } # for (ss ...)

  res;
})


############################################################################
# HISTORY:
# 2009-10-26
# o Resampling with replacement now allowed (implicitly through '...').
# 2009-06-30
# o Created.
############################################################################
HenrikBengtsson/aroma.cn.eval documentation built on June 13, 2019, 10:17 a.m.