Title: | Generate Random Given and Surnames |
---|---|
Description: | Function for generating random gender and ethnicity correct first and/or last names. Names are chosen proportionally based upon their probability of appearing in a large scale data base of real names. |
Authors: | Damian W. Betebenner [aut, cre] , Lambert Joshua [ctb] |
Maintainer: | Damian W. Betebenner <[email protected]> |
License: | GPL-3 |
Version: | 1.6-0.0 |
Built: | 2024-11-13 05:59:54 UTC |
Source: | https://github.com/centerforassessment/randomnames |
Functions for generating random gender and ethnicity correct first and/or last names where names are proportionally sampled based upon their frequency in a large scale database.
Package: | randomNames |
Type: | Package |
Version: | 1.6-0.0 |
Date: | 2024-5-2 |
License: | GPL-3 |
LazyLoad: | yes |
Damian W. Betebenner [email protected]
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)
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.
Damian W. Betebenner [email protected]
randomNames() ## Returns a single name in "last, first" format randomNames(5, which.names="first") ## Returns 5 first names randomNames(5, return.complete.data=TRUE) ## Returns entire data.table 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) 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)
randomNames() ## Returns a single name in "last, first" format randomNames(5, which.names="first") ## Returns 5 first names randomNames(5, return.complete.data=TRUE) ## Returns entire data.table 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) 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)
A dataset compiled from a large scale data set of names providing first names by gender and ethnicity and last names by ethnicity. The dataset provides
frequency probabilities from the original data set so that sampling provides a reasonable set of random names. The dataset is for use with the
randomNames
function to quickly generate random names that can be used, for example, to anonymize results.
An environment of first and last names by gender and ethnicity (first names) and ethnicity (last names)
Gender is coded 0 for male and 1 for female, ethnicity is coded 1 for American Indian or Native Alaskan,
2 for Asian or Pacific Islander, 3 for Black (not Hispanic), 4 for Hispanic, and 5 for White (not
Hispanic). For example, the array first_names_e1_g0
in randomNamesData
provides first
and associated frequency probabilities for male, American Indians or Native Alaskans. To view names of
all environment arrays type ls(randomNamesData)
after loading the package.
Large scale state data