-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_set_years.R
43 lines (36 loc) · 992 Bytes
/
sub_set_years.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#'
#'
#'
#' Helper function for selecting points for an axis so not all are necessary
#'
#' @description {
#' Takes an array and subsamples it every n places. Many times there are so many years the labels on
#' the plot overlap. This function returns the position and label for
#' the subset. The function can be used on any type of simple array.
#'}
#' @param years an array of years
#' @return a list containing:
#' \code{position} array of axis positions
#' \code{label} array of labels
#'
#' @author Paul Whitfield <[email protected]>
#'
#' @export
#'
#'
#' @example
#' myears <- c(1900:2045)
#' myears <-sub_set_Years(myears,20)
#' myears
#'
#' a <-LETTERS
#' my_alpha <- sub_set_Years(a,5)
#' my_alpha
sub_set_Years <- function(years,n) {
pts <- c(1:length(years))
pts<-pts[1:(length(years)/n)*n]
years <- years[pts]
result <- list(pts, years)
names(result) <-c("position","label")
return(result)
}