Description Usage Arguments Note Author(s) References Examples
The RandomNames function uses data from the Genealogy
Data: Frequently Occurring Surnames from Census 1990–Names Files web page
to generate a data.frame with random names.
1 2 |
N |
The number of random names you want. Defaults to 100. |
cat |
Do you want "common" names, "rare" names, names with an "average"
frequency, or some combination of these? Should be specified as a character
vector (for example, |
gender |
Do you want first names from the "male" dataset, the "female"
dataset, or from all available names? Should be specified as a quoted string
(for example, |
MFprob |
What proportion of the sample should be male names and what
proportion should be female? Specify as a numeric vector that sums to 1 (for
example, |
dataset |
What do you want to use as the dataset of names from which to sample? A default dataset is provided that can generate over 400 million unique names. See the "Dataset Details" note for more information. |
Dataset Details This function samples from a provided dataset
of names. By default, it uses the data from the Genealogy Data:
Frequently Occurring Surnames from Census 1990–Names Files web page. Those
data have been converted to list named "CensusNames1990"
containing three data.frames (named "surnames",
"malenames", and "femalenames").
Alternatively, you may provide your own data in a list formatted
according to the following specifications (see the "myCustomNames"
data in the "Examples*" section). Please remember that R is case
sensitive!
This must be a named list with three items:
"surnames", "malenames", and "femalenames".
The
contents of each list item is a data.frame with at least the
following named columns: "Name" and "Category".
Acceptable values for "Category" are "common", "rare",
and "average".
Ananda Mahto
See http://www.census.gov/genealogy/www/data/1990surnames/names_files.html for source of data.
Inspired by the online Random Name Generator http://random-name-generator.info/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # Generate 20 random names
RandomNames(N = 20)
# Generate a reproducible list of 100 random names with approximately
# 80% of the names being female names, and 20% being male names.
set.seed(1)
temp <- RandomNames(cat = "common", MFprob = c(.2, .8))
list(head(temp), tail(temp))
table(temp$Gender)
# Cleanup
rm(.Random.seed, envir=globalenv()) # Resets your seed
rm(temp)
# Generate 10 names from the common and rare categories of names
RandomNames(N = 10, cat = c("common", "rare"))
## ===================================== ##
## ======== USING YOUR OWN DATA ======== ##
myCustomNames <- list(
surnames = data.frame(
Name = LETTERS[1:26],
Category = c(rep("rare", 10), rep("average", 10), rep("common", 6))),
malenames = data.frame(
Name = letters[1:10],
Category = c(rep("rare", 4), rep("average", 4), rep("common", 2))),
femalenames = data.frame(
Name = letters[11:26],
Category = c(rep("rare", 8), rep("average", 4), rep("common", 4))))
str(myCustomNames)
RandomNames(N = 15, dataset = myCustomNames)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.