Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
string combinations
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`)

This comment has been minimized.

Copy link
Owner Author

@grosscol grosscol commented Feb 1, 2019

> lapply(X=split_list, FUN=`make_combinations`)
[1] "fname lname midname" "fname midname lname" "lname fname midname" "lname midname fname" "midname fname lname" "midname lname fname"

[1] "doe e john" "doe john e" "e doe john" "e john doe" "john doe e" "john e doe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.