Created
December 2, 2021 22:47
-
-
Save opplatek/1874f044d3bbed0cf19aedf86fb3d6fe to your computer and use it in GitHub Desktop.
Splitting vector into smaller chunks by a separator and extracting chunk(s)
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
# | |
# Splitting vector into smaller chunks by a separator and extracting chunk(s) | |
# | |
split_vector <- function (x, sep, column){ | |
# sapply(x, function(x) strsplit(x, split = sep, fixed = T)[[1]][column], USE.NAMES = F) | |
unlist(lapply(x, function(x) strsplit(x, sep, fixed = T)[[1]][column])) | |
} | |
# Test | |
vect <- c("a.b.c", "d.e.f") | |
split_vector(vect, ".", 2) | |
[1] "b" "e" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment