Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my_alphs <- c("X","Y","Z")
- my_str <- "LA**"
- # Note that the length of the string can be longer than 4 and
- # the position of the asterisk can be anywhere with different length
- LAXX
- LAXY
- LAXZ
- LAYX
- LAYY
- LAYZ
- LAZX
- LAZY
- LAZZ
- library(dplyr)
- expand.grid(my_alphs, my_alphs) %>%
- mutate(var = paste0(gsub('\**', "", my_str), Var1, Var2)) %>%
- select(var)
- #var
- #1 LAXX
- #2 LAYX
- #3 LAZX
- #4 LAXY
- #5 LAYY
- #6 LAZY
- #7 LAXZ
- #8 LAYZ
- #9 LAZZ
- expand.grid(my_alphs, my_alphs) %>%
- mutate(var = paste0(gsub('\**', "", my_str), Var1, Var2)) %>%
- select(var) %>%
- pull
- #[1] "LAXX" "LAYX" "LAZX" "LAXY" "LAYY" "LAZY" "LAXZ" "LAYZ"
- #[9] "LAZZ"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement