After installing the package from either CRAN or GitHub, itâs simple to generate random names using the following simple instructions.
By default, the randomNames
function supplies a single random last and first name separated by a comma:
To generate more random names, just supply a positive integer to the randomNames
function:
The randomNames function accepts several arguments including n
, gender
, ethnicity
, which.names
, name.order
, and name.sep
.
randomNames(n,
gender,
ethnicity,
which.names="both",
name.order="last.first",
name.sep=", ",
sample.with.replacement=TRUE,
return.complete.data=FALSE)
For complete documentation on values accepted for arguments, see the function documentation
ExamplesThe first argument, n
, controls the number of names returned by the randomNames function:
> randomNames(5) ## 5 last, first names
[1] "Bayona, Christopher" "Valentine, Allison" "Sandoval, Joseph" "Avants, Kali" "Elliott, Kharim"
The second argument, gender
, controls the gender (0=male, 1=female) of the first names returned. This argument can be a vector up to the same length as the number of names requested.
> randomNames(5, gender=1) ## 5 female last, first names
[1] "Siu, Abigail" "Lizardo, Elsa" "Wilcox, Taylor" "Sinath, Christine" "Zamora, Waylene"
>
> randomNames(5, gender=c(0,0,1,1,1)) ## 2 male and 3 female last, first names
[1] "Alcocer, John" "al-Hannan, Abdul Fattaah" "el-Zaki, Khaira" "Brown, Kelsie" "Stoor, Mickela"
The third argument, ethnicity
, controls the ethnicity of the names returned. The following integer codes/ethnicities are accepted:
> randomNames(5, gender=0, ethnicity=3) ## 5 African American, male last, first names
[1] "Magraff, Robert" "Fortenberry, Elijah" "Adams, Eli" "Henderson, Seiko" "Teshome, Patrick"
The fourth argument, which.names
controls which names are returned. The argument accepts the values: both
(the default), last
, first
, or complete.data
> randomNames(5, gender=1, ethnicity=6, which.names="first") ## 5 Middle Eastern/Arabic, female first names
[1] "Shafee'a" "Fareeda" "Nusaiba" "Fidda" "Mu'hsina"
The fifth argument, name.order
, controls the order in which the names are returned. The argument is only relevant if which.names=both
. The argument accepts the values: last.first
(the default) and first.last
.
> randomNames(5, gender=1, ethnicity=6, name.order="first.last") ## 5 first last names
[1] "Awaatif, al-Rafiq" "Aadila, al-Koroma" "Husniyya, al-Shahan" "Khairiya, el-Barakat" "Mutee'a, el-Atallah"
The sixth argument, name.sep
, is a character string that controls the separator used when both names are returned. The default separator is ,
.
> randomNames(5, gender=1, ethnicity=6, name.order="first.last", name.sep=" ") ## 5 first last names separated by a space
[1] "Mu'mina al-Qasim" "Shadhaa el-Siddiqui" "Shameema al-Hakim" "Sireen el-Hameed" "Sulama el-Ebrahim"
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4