Function to generate random gender and ethnicity correct first and/or last names. Names are chosen proportionally based upon their probability of appearing in a large scale database of real names. Function to generate random gender and ethnicity correct first and/or/last names. The function probabilistically samples from the embedded randomNamesData dataset to provide a realistic list of first and/or last names.
randomNames(n, gender, ethnicity, which.names="both", name.order="last.first", name.sep=", ", sample.with.replacement=TRUE, return.complete.data=FALSE)
| n | OPTIONAL. Positive integer indicating how many name to produce. Best to use when no gender or ethnicity data is provided and one simply wants |
|---|---|
| gender | OPTIONAL. A vector indicating the genders for the names to be calculated. The maximum of |
| ethnicity | OPTIONAL. A vector indicating the ethnicities for the names to be calculated. The maximum of
|
| which.names | OPTIONAL. One of |
| name.order | OPTIONAL. If |
| name.sep | OPTIONAL. If |
| sample.with.replacement | Boolean argument (defaults to TRUE) indicating whether sampling is done with replacement. |
| return.complete.data | Boolean argument (defaults to FALSE) indicating whether to return data including gender and ethnicity codes used for name construct. If set to TRUE, data is returned as a data.frame/data.table. |
Typical use of the function is to submit a vector of genders and ethnicities to derived a gender and ethnicity representative vector of first and/or last names.
Function returns a character vector containing first and/or last names.
randomNames() ## Returns a single name in "last, first" format#> [1] "al-Hai, Musaddiq"randomNames(5, which.names="first") ## Returns 5 first names#> [1] "Connor" "Abdul Kader" "Faran" "Dakota" "Katie"randomNames(5, return.complete.data=TRUE) ## Returns entire data.table#> gender ethnicity first_name last_name #> 1: 1 6 Rafeeqa al-Harron #> 2: 0 5 Noah Telschow #> 3: 1 1 Diana Yellowhawk #> 4: 1 4 Jerika Payne #> 5: 0 5 Jacob Seltingtest.df <- data.frame(GENDER=sample(0:1, 100, replace=TRUE), ETHNICITY=sample(1:6, 100, replace=TRUE)) test.names <- randomNames(gender=test.df$GENDER, ethnicity=test.df$ETHNICITY) head(test.names)#> [1] "al-Saadeh, Baaqir" "Padilla, Danielle" "al-Mahmoud, Zaaid" #> [4] "Vergara, Marisela" "Lee, Cordelia" "al-Zaman, Ikram"ethnicities <- c("African American", "Hispanic", "Asian", "White", "Native American") genders <- c("Female", "Male") test.df <- data.frame(GENDER=sample(genders, 100, replace=TRUE), ETHNICITY=sample(ethnicities, 100, replace=TRUE)) test.names <- randomNames(gender=test.df$GENDER, ethnicity=test.df$ETHNICITY) head(test.names)#> [1] "Teutonico, Alex" "Raje, Siran" "Serrano, Avishek" "Thompson, Selam" #> [5] "Hale, Lauren" "Lugo III, Cade"