R/simulationGroup.R

Defines functions .simulationGroup simulationGroup

Documented in simulationGroup

simulationGroup <- function(x, n){
  if(inherits(x, what="mistatSimulation", which=FALSE)){
    res <- .simulationGroup(x, n)
    return(res)
  } else
    stop("x must inherits from class mistatSimulation")
}

.simulationGroup <- function(x, n){
  group <- rep(
    ceiling(nrow(x)/n):1, 
    each=n)[nrow(x):1]
  res <- data.frame(x, group=factor(group))
  n2 <- aggregate(res$group, by=res["group"], FUN=length)
  if(n2$x[1] < n){
    res <- res[-(1:n2$x[1]),]
    warning(paste("discarded first", n2$x[1],
                  "observations because nrow(x) is not a multiple of n"))
  }
  return(res)
}

Try the mistat package in your browser

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

mistat documentation built on March 7, 2023, 6:43 p.m.