Question: **My start on an example**:

```
yr_min <- 20181
yr_max <- 20195

as.numeric(paste0(rep(
  seq(as.numeric(substr(yr_min, 1, 4)), 
      as.numeric(substr(yr_max, 1, 4))), 
  each = 3),
  c(1, 3, 5)))

[1] 20181 20183 20185 20191 20193 20195

```

**What is wrong with the above code**? It will not generalize beyond situations where `yr_min` ends in a `1` and `yr_max` ends in a `5`.

For example:

```
yr_min <- 20183
yr_max <- 20193

as.numeric(paste0(rep(
  seq(as.numeric(substr(yr_min, 1, 4)), 
      as.numeric(substr(yr_max, 1, 4))), 
  each = 3),
  c(1, 3, 5)))

[1] 20181 20183 20185 20191 20193 20195

```

The desired output is 

```
[1] 20183 20185 20191 20193

```

Answer: 
1) Generate the entire sequence of years then `Filter()` out anything which isn't 1,3,5 modulo 10.

```
rem_135_mod10 <- function(x) { (x %% 10) %in% c(1,3,5) }

Filter(rem_135_mod10, seq(yr_min, yr_max))
# 20181 20183 20185 20191 20193 20195

```

* This is functional programming in R with the constructs [Filter(), Map(), Reduce()...](https://stat.ethz.ch/R-manual/R-devel/library/base/html/funprog.html))
* as the others say, for these specific remainders 1,3,5, you can exploit that you only need step 2: `seq(yr_min, yr_max, by=2)`

or 2) generate the sequence of base decades 20180, 20190... and add the offsets 1,3,5 yourself. Same difference.
predefined data:

```
end_vec <- c(1, 3, 5)
yr_min  <- 20183
yr_max  <- 20193

```

code:

```
ans<-
c(
sapply(c(yr_min, yr_max), function(x) {n<-nchar(x);as.numeric(paste0(substr(x,1,n-1),end_vec))})
)

ans[dplyr::between(ans, yr_min, yr_max)]

```

result:

```
# [1] 20183 20185 20191 20193

```