Function to estimate the age from a first name. Connects directly to the agify.io API sending a request with a name and parses the response to return the predicted age.

agify(
  name,
  country_id = NULL,
  simplify = TRUE,
  apikey = get_api_key(),
  meta = FALSE
)

Arguments

name

Name/s to estimate the age. Can be a single character string or a character vector. Obligatory parameter.

country_id

Responses will in a lot of cases be more accurate if the data is narrowed to a specific country. This optional parameter allows to specify a specific country. The parameter must be a country code following the common ISO 3166-1 alpha-2 country code convention. To see a list of the supported countries use the supported_countries function or visit the following link.

simplify

Logical parameter, which defines if the result should be returned as a character vector or a data.frame with additional information. By default set to TRUE, which returns a vector.

apikey

Optional parameter to pass the API key. The API is free for up to 1000 names/day. No sign up or API key needed. Yet, if more requests would be needed, visit the agify.io store and the obtained API key can be passed through this parameter. The API can also be saved one time through the save_api_key function, so it is not necessary to call again.

meta

Logical parameter to define if API related information should be returned. By default set to FALSE. Returns information about:

  • The amount of names available in the current time window

  • The number of names left in the current time window

  • Seconds remaining until a new time window opens

Value

The estimated age in a single character vector form or a data.frame with additional information.

Details

The function automatically handles pagination (max. 10 names per API request), missing values & duplicated values. If a name is duplicated for the same country_id (if given), it will handle the request as a a single name to save requests, returning the same value for the duplicated names. To see more details about the API documentation, visit the agify.io website.

Warning

Please be aware about local privacy protection regulations such as GDPR when dealing with personal data.

See also

Examples

# \donttest{ agify(name=c("Ben", "Maria"))
#> [1] 48 21
# }