Skip to content

Instantly share code, notes, and snippets.

@martinctc
Created August 8, 2019 16:56
Show Gist options
  • Save martinctc/56b3fb701a182f5b8dffceecd65b6d86 to your computer and use it in GitHub Desktop.
Save martinctc/56b3fb701a182f5b8dffceecd65b6d86 to your computer and use it in GitHub Desktop.
[Sort letters in a character string by alphabetical order] #R
#' 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