Created
February 1, 2019 13:55
-
-
Save grosscol/d6c9c0408391c3e00645dd602e3e3f8a to your computer and use it in GitHub Desktop.
string combinations
This file contains hidden or 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
library(gtools) | |
demo_input <- c("fname midname lname","doe john e") #only 2 'names' in this example list. | |
split_list <- strsplit(demo_input, " |-") | |
make_combinations <- function(x){ | |
# Use permutations from the gtools package | |
name_grid <- permutations(3,3,x) | |
apply(X=name_grid, MARGIN=1, FUN=paste0, collapse=' ') | |
} | |
lapply(X=split_list, FUN=`make_combinations`) |
Author
grosscol
commented
Feb 1, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment