Learn R Programming

randomNames (version 0.1-0)

randomNames: Random Names Function

Description

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 data base 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.

Usage

randomNames(n, gender, ethnicity, which.names="both", name.order="last.first", name.sep=", ")

Arguments

n
OPTIONAL. Integer indicating how many name to produce. Best to use when no gender or ethnicity data is provided and one simple wants n random first and/or last names.
gender
OPTIONAL. A vector indicating the genders for the names to be calcualted. 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. See examples for various use cases.
ethnicity
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. See examples for various use cases.
which.names
OPTIONAL. One of "both" (the default), "first", or "last" indicating what names to produce.
name.order
OPTIONAL. If which.names is "both", then names can be returned as either "last.first" (the default) or "first.last".
name.sep
OPTIONAL. If which.names is "both", then names are separated by the name.sep string provided. Defaults to comma-space separated.

Value

Details

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.

See Also

randomNamesData

Examples

Run this code
randomNames()  ## Returns a single name in "last, first" format

randomNames(5, which.names="first") ## Returns 5 first names

test.df <- data.frame(GENDER=round(runif(100)),
	ETHNICITY=round(runif(100,min=1, max=5)))

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)

Run the code above in your browser using DataLab