Created
August 8, 2019 16:56
-
-
Save martinctc/56b3fb701a182f5b8dffceecd65b6d86 to your computer and use it in GitHub Desktop.
[Sort letters in a character string by alphabetical order] #R
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
#' Sorts letters in a character string by alphabetical order | |
#' | |
#' Vectorised | |
str_arrange <- function(x){ | |
x %>% | |
stringr::str_split("") %>% # Split string into letters | |
purrr::map(~sort(.) %>% paste(collapse = "")) %>% # Sort and re-combine | |
as_vector() # Convert list into vector | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment