Created
March 20, 2014 17:55
-
-
Save timriffe/9669897 to your computer and use it in GitHub Desktop.
aggN() aggregate vector of single age (year) data to N-year groups
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
#' | |
#' @title aggN aggregate vector of single age (year) data to N-year groups | |
#' | |
#' @description This only makes sense if N is 5 or 10 (or 2 I guess), since it uses modulo to find groups | |
#' Ages are assumed to start at 0 and count up in single ages. | |
#' | |
#' @param x the vector of single-age-classified data | |
#' @param N desired width of interval, e.g., 5 or 10 | |
#' | |
#' @export | |
#' | |
aggN <- function(x,N){ | |
age <- 0:(length(x) - 1) | |
tapply(x,age - age %% N, sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment