r - Splitting strings then pasting them randomly together -


i have 2 vectors:

presidents = c("bill clinton", "george bush", "ronald reagan", "jimmy carter", "gerald ford")  vice.presidents = vice.presidents = c("al gore", "dan quayle", "george bush","walter mondale", "nelson rockefeller") 

i trying results using substr() of form "clinton+quayle", "bush+..." last names , randomly selected president paired randomly selected vice president.

try following.

set.seed(1843) p <- sapply(strsplit(presidents, " "), '[', 2) vp <- sapply(strsplit(vice.presidents, " "), '[', 2) n <- 5 paste(sample(p, n, true), sample(vp, n, true)) 

first, split names white-space , keep 2nd part, last name.
then, sample @ random result vectors , paste them together.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -