Skip to content

Instantly share code, notes, and snippets.

@pavel-filatov
Created August 11, 2018 16:01
Show Gist options
  • Save pavel-filatov/d6a8bf38dd7ce329cf441004d84e4f54 to your computer and use it in GitHub Desktop.
Save pavel-filatov/d6a8bf38dd7ce329cf441004d84e4f54 to your computer and use it in GitHub Desktop.
couple_vector <- function(x) {
couple_vector_iter <- function(y, acc) {
if (length(y) > 0) {
couple_vector_iter(y[-c(1:2)], c(acc, list(y[1:2])))
} else {
acc
}
}
couple_vector_iter(x, NULL)
}
couple_vector(1:10)
#> [[1]]
#> [1] 1 2
#>
#> [[2]]
#> [1] 3 4
#>
#> [[3]]
#> [1] 5 6
#>
#> [[4]]
#> [1] 7 8
#>
#> [[5]]
#> [1] 9 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment