Created
August 11, 2018 16:01
-
-
Save pavel-filatov/d6a8bf38dd7ce329cf441004d84e4f54 to your computer and use it in GitHub Desktop.
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
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