R/splitgrp.R

Defines functions splitgrp

Documented in splitgrp

# vim: set noexpandtab tabstop=2:
#' Split a list with size n into groups with at least m elements
#'
#' Split a list with size n into groups with at least m elements
#'
#' @param n an integer indicating the total length
#' @param m the min group size
#' @keywords category
#' @export
#' @examples
#' 
#' splitgrp(1, 2)
#' splitgrp(2, 2)
#' splitgrp(3, 2)
splitgrp=function(n, m) {
	x = seq_len(n)
	if(n < m) {
		list(`1`=x)
	} else {
		grp_ids = seq_len(floor(n/m))
		grp_lens=sapply(
			suppressWarnings(split(x, grp_ids))
			, length
			)
		split(x
			, rep(grp_ids, grp_lens)
			)
	}
}

Try the l1kdeconv package in your browser

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

l1kdeconv documentation built on May 2, 2019, 10:16 a.m.