randomNames(n, gender, ethnicity, which.names="both", name.order="last.first", name.sep=", ", sample.with.replacement=TRUE, return.complete.data=FALSE)Arguments 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 n
random first and/or last names.
OPTIONAL. A vector indicating the genders for the names to be calculated. The maximum of n
, the length of gender
and the length of ethnicity
is the number of random names returned. Note that the gender vector is only employed for deriving first names. If no gender vector is provided, the function randomly samples from both genders to produce a sample of names. Current gender codes are 0: Male
and 1: Female
. See examples for various use cases.
OPTIONAL. A vector indicating the ethnicities for the names to be calculated. The maximum of n
, the length of gender
and the length of ethnicity
is the number of random names returned. Note that the ethnicity vector is employed for both deriving first and last names. If no ethnicity vector is provided the function samples from all ethnicity to produce a sample of names. Current ethnicity codes are:
American Indian or Native Alaskan
Asian or Pacific Islander
Black (not Hispanic)
Hispanic
White (not Hispanic)
Middle-Eastern, Arabic
OPTIONAL. One of "both"
(the default), "first"
, or "last"
, "complete.data"
indicating what names to produce. "complete.data"
provides a data.table with ethnicity
and gender
codes.
OPTIONAL. If which.names
is "both"
, then names can be returned as either "last.first"
(the default) or "first.last"
.
OPTIONAL. If which.names
is "both"
, then names are separated by the name.sep
string provided. Defaults to comma-space separated.
Boolean argument (defaults to TRUE) indicating whether sampling is done with replacement.
return.complete.dataBoolean 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.
DetailsTypical 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.
ValueFunction returns a character vector containing first and/or last names.
See also ExamplesrandomNames() ## Returns a single name in "last, first" format
#> [1] "Caudillo, Jerel"
randomNames(5, which.names="first") ## Returns 5 first names
#> [1] "Patrick" "Randall" "San" "Caitlin" "Zaidaan"
randomNames(5, return.complete.data=TRUE) ## Returns entire data.table
#> gender ethnicity first_name last_name #> 1: 0 1 Mahpiya Rockwell #> 2: 1 6 Mastoora el-Mohamed #> 3: 1 3 Myoni Hale #> 4: 1 5 Shayla Dunn #> 5: 0 6 Muaaid al-Hamid
test.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] "Palmier, Mackenzie" "el-Abraham, Mardiyya" "Hysaw, Dante" #> [4] "Ayala, Karla" "Coleman, Abeni" "Sahai, Yer"
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] "Landin, Anthony" "Gutierrez, Alexandria" "Lobato, Andrew" #> [4] "Mccallum, Hannah" "Nelson, Lolita" "Prinzi, Cali"
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