## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(ezrsurvey)

## -----------------------------------------------------------------------------
recode_region(c("United States", "USA", "U.S.", "Estados Unidos"))

## -----------------------------------------------------------------------------
recode_region(c("England", "Scotland", "Wales", "Northern Ireland"))

## -----------------------------------------------------------------------------
recode_region(c("Deutschland", "Brasil", "Espana", "Osterreich"))

## -----------------------------------------------------------------------------
recode_region(c("Viet Nam", "Syrian Arab Republic", "Republic of Moldova",
                "Cabo Verde", "Eswatini"))

## -----------------------------------------------------------------------------
recode_region(c("Côte d'Ivoire", "Réunion", "Türkiye"))

## -----------------------------------------------------------------------------
survey <- add_region(podracing_survey, demo_country, subregion = TRUE)

calc_percentage(survey, region, sort = "desc")

## -----------------------------------------------------------------------------
calc_percentage(survey, subregion, sort = "desc")

## -----------------------------------------------------------------------------
recode_region(c("US", "GBR", "DE", "JPN", "AUS"))

## -----------------------------------------------------------------------------
recode_region(c("NO", "no"), quiet = TRUE)

## -----------------------------------------------------------------------------
head(country_region)

## -----------------------------------------------------------------------------
survey %>%
  dplyr::left_join(dplyr::select(country_region, country, iso2, iso3),
                   by = c("demo_country" = "country")) %>%
  dplyr::count(iso3, region, sort = TRUE) %>%
  head(8)

## -----------------------------------------------------------------------------
convert_currency(50000, from = "GBP", to = "USD")
convert_currency(c(50000, 60000), from = c("EUR", "CAD"), to = "USD")

## -----------------------------------------------------------------------------
pay <- tibble::tibble(
  respondent = 1:5,
  salary = c(52000, 61000, 48000, 75000, 39000),
  currency = c("GBP", "EUR", "USD", "CAD", "AUD")
)

add_currency(pay, salary, from = currency, to = "EUR", into = "salary_eur")

## -----------------------------------------------------------------------------
head(list_currencies())

## -----------------------------------------------------------------------------
own_rates <- c(USD = 1, GBP = 0.79, EUR = 0.92)
convert_currency(50000, from = "GBP", to = "EUR", rates = own_rates)

