Use this vector: c("alex john cardazzi", "jeremy william barbara", "nate crawford moon", "jordan scott elam", "julius randle")

namez <- c("alex john cardazzi", "jeremy william barbara", "nate crawford moon", "jordan scott elam", "julius randle")
gsub("\\s.+", "", namez)
## [1] "alex"   "jeremy" "nate"   "jordan" "julius"
gsub("[[:alpha:]]+\\s", "", namez)
## [1] "cardazzi" "barbara"  "moon"     "elam"     "randle"
gsub("\\s$", "", gsub("^[[:alpha:]]+\\s|[[:alpha:]]+$", "", namez))
## [1] "john"     "william"  "crawford" "scott"    ""
paste0(gsub("[[:alpha:]]+\\s", "", namez),
       "-",
       gsub("\\s.+", "", namez),
       ifelse(gsub("\\s$", "", gsub("^[[:alpha:]]+\\s|[[:alpha:]]+$", "", namez)) == "", "", "-"),
       gsub("\\s$", "", gsub("^[[:alpha:]]+\\s|[[:alpha:]]+$", "", namez)))
## [1] "cardazzi-alex-john"     "barbara-jeremy-william" "moon-nate-crawford"    
## [4] "elam-jordan-scott"      "randle-julius"
pword <- "ny"
timeNow <- Sys.time()
success <- 0
counter1 <- 1
while(success == 0){
  
  l1 <- letters[counter1]
  counter2 <- 1
  while(success == 0 & counter2 < 27){
    
    l2 <- letters[counter2]
    # cat("\r", paste0(l1, l2))
    if(paste0(l1, l2) == "ny"){
      
      success <- 1
    } else {
      
      counter2 <- counter2 + 1
    }
  }
  
  counter1 <- counter1 + 1
}


print(Sys.time() - timeNow)
## Time difference of 0.03474283 secs
pyramid <- function(the_char, size){
  
  for(i in 1:size){
  
    if(i == size){
      
      vec <- paste0(paste(rep(the_char, i), collapse = ""), "x")
    } else {
      
      vec <- paste(rep(the_char, i), collapse = "")
    }
    
    print(vec)
  }
  for(i in (size-1):1){
    
    print(paste(rep(the_char, i), collapse = ""))
  }
}

pyramid(the_char = "a", size = 5)
## [1] "a"
## [1] "aa"
## [1] "aaa"
## [1] "aaaa"
## [1] "aaaaax"
## [1] "aaaa"
## [1] "aaa"
## [1] "aa"
## [1] "a"