R/sub_window.R

Defines functions sub_window

Documented in sub_window

#' sub_window function
#'
#' @param matrix binary matrix consisting of 1's and 0's.
#' @param width number of columns for each subwindow
#'
#' @return a list of non-overlapping, equally sized windows
#' @export
#'
#' @examples x=window(matrix,width)
#' @importFrom magrittr %>%

#account for slightly uneven windows

sub_window<-function(matrix,width){
  begin=1
  sub_win=list()

  #adjust so we don't get floating points as indicies
  num_windows=ceiling(ncol(matrix)/width)

  for(i in 1:num_windows){
    if(i==num_windows){
      sub_win[[i]]=matrix[,(begin:(ncol(matrix)))]
      return(sub_win)
    }
    sub_win[[i]]=matrix[,(begin:(width*i))]
    begin=width*i+1
  }
}
deponent-verb/popgen.stats documentation built on Nov. 4, 2019, 10:26 a.m.