Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. my_alphs <- c("X","Y","Z")
  2.  
  3. my_str <- "LA**"
  4. # Note that the length of the string can be longer than 4 and
  5. # the position of the asterisk can be anywhere with different length
  6.  
  7. LAXX
  8. LAXY
  9. LAXZ
  10. LAYX
  11. LAYY
  12. LAYZ
  13. LAZX
  14. LAZY
  15. LAZZ
  16.  
  17. library(dplyr)
  18.  
  19. expand.grid(my_alphs, my_alphs) %>%
  20. mutate(var = paste0(gsub('\**', "", my_str), Var1, Var2)) %>%
  21. select(var)
  22.  
  23. #var
  24. #1 LAXX
  25. #2 LAYX
  26. #3 LAZX
  27. #4 LAXY
  28. #5 LAYY
  29. #6 LAZY
  30. #7 LAXZ
  31. #8 LAYZ
  32. #9 LAZZ
  33.  
  34. expand.grid(my_alphs, my_alphs) %>%
  35. mutate(var = paste0(gsub('\**', "", my_str), Var1, Var2)) %>%
  36. select(var) %>%
  37. pull
  38.  
  39. #[1] "LAXX" "LAYX" "LAZX" "LAXY" "LAYY" "LAZY" "LAXZ" "LAYZ"
  40. #[9] "LAZZ"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement