Uses 'birth_year' (from cust) and 'year' (from sale) to identify age for each license year

recode_agecat(dat, age_labs = c("0-17", "18-24", "25-34", "35-44",
  "45-54", "55-64", "65+"), age_breaks = c(-Inf, 17, 24, 34, 44, 54, 64,
  Inf), max_age = 110, suppress_check = TRUE)

Arguments

dat

data frame: Input table

age_labs

character: labels to use for age category

age_breaks

numeric: breaks for age category passed to cut

max_age

numeric: maximum allowed age. Anything above will be set to missing.

suppress_check

logical: If TRUE, does not print a coding summary

See also

Salic Function Reference: salic

Other functions for working with category variables: df_factor_var, factor_var, label_categories

Examples

library(dplyr) data(history) x <- recode_agecat(history, suppress_check = FALSE)
#> #> Category Coding Summary: #> age_year age agecat n #> 0 1 0-17 2 #> 1 1 0-17 16 #> 2 1 0-17 17 #> 3 1 0-17 17 #> 4 1 0-17 15 #> 5 1 0-17 17 #> 6 1 0-17 18 #> 7 1 0-17 19 #> 8 1 0-17 29 #> 9 1 0-17 43 #> 10 1 0-17 61 #> 11 1 0-17 53 #> 12 1 0-17 81 #> 13 1 0-17 93 #> 14 1 0-17 86 #> 15 1 0-17 114 #> 16 1 0-17 721 #> 17 1 0-17 1201 #> 18 2 18-24 1279 #> 19 2 18-24 1328 #> 20 2 18-24 1385 #> 21 2 18-24 1306 #> 22 2 18-24 1395 #> 23 2 18-24 1421 #> 24 2 18-24 1413 #> 25 3 25-34 1394 #> 26 3 25-34 1444 #> 27 3 25-34 1485 #> 28 3 25-34 1544 #> 29 3 25-34 1520 #> 30 3 25-34 1490 #> 31 3 25-34 1522 #> 32 3 25-34 1468 #> 33 3 25-34 1494 #> 34 3 25-34 1489 #> 35 4 35-44 1513 #> 36 4 35-44 1536 #> 37 4 35-44 1596 #> 38 4 35-44 1619 #> 39 4 35-44 1662 #> 40 4 35-44 1658 #> 41 4 35-44 1681 #> 42 4 35-44 1722 #> 43 4 35-44 1730 #> 44 4 35-44 1763 #> 45 5 45-54 1726 #> 46 5 45-54 1691 #> 47 5 45-54 1752 #> 48 5 45-54 1750 #> 49 5 45-54 1719 #> 50 5 45-54 1656 #> 51 5 45-54 1688 #> 52 5 45-54 1709 #> 53 5 45-54 1716 #> 54 5 45-54 1820 #> 55 6 55-64 1729 #> 56 6 55-64 1642 #> 57 6 55-64 1594 #> 58 6 55-64 1598 #> 59 6 55-64 1543 #> 60 6 55-64 1525 #> 61 6 55-64 1508 #> 62 6 55-64 1516 #> 63 6 55-64 1417 #> 64 6 55-64 1400 #> 65 7 65+ 1556 #> 66 7 65+ 1605 #> 67 7 65+ 1566 #> 68 7 65+ 1530 #> 69 7 65+ 1419 #> 70 7 65+ 1295 #> 71 7 65+ 1138 #> 72 7 65+ 934 #> 73 7 65+ 780 #> 74 7 65+ 627 #> 75 7 65+ 480 #> 76 7 65+ 316 #> 77 7 65+ 237 #> 78 7 65+ 140 #> 79 7 65+ 112 #> 80 7 65+ 87 #> 81 7 65+ 82 #> 82 7 65+ 61 #> 83 7 65+ 48 #> 84 7 65+ 39 #> 85 7 65+ 26 #> 86 7 65+ 13 #> 87 7 65+ 14 #> 88 7 65+ 8 #> 89 7 65+ 4 #> 90 7 65+ 2 #> 91 7 65+ 3 #> 92 7 65+ 1 #> 93 7 65+ 2 #> 94 7 65+ 1 #> 97 7 65+ 1 #> 100 7 65+ 1 #> NA NA <NA> 1619