Returns code translations for categorical variables, which appear in most NHANES tables.

nhanesTranslate(
  nh_table,
  colnames = NULL,
  data = NULL,
  nchar = 128,
  mincategories = 1,
  details = FALSE,
  dxa = FALSE,
  cleanse_numeric = FALSE
)

Arguments

nh_table

The name of the NHANES table to retrieve.

colnames

The names of the columns to translate. It will translate all the columns by default.

data

If a data frame is passed, then code translation will be applied directly to the data frame.
In that case the return argument is the code-translated data frame.

nchar

Applies only when data is defined. Code translations can be very long.
Truncate the length by setting nchar (default = 128).

mincategories

The minimum number of categories needed for code translations to be applied to the data (default=1).

details

If TRUE then all available table translation information is displayed (default=FALSE).

dxa

If TRUE then the 2005-2006 DXA translation table will be used (default=FALSE).

cleanse_numeric

Logical flag. If TRUE, some special codes in numeric variables, such as ‘Refused’ and ‘Don't know’ will be converted to NA.

Value

The code translation table (or translated data frame when data is defined). Returns NULL upon error.

Details

Most NHANES data tables have encoded values. E.g. 1 = 'Male', 2 = 'Female'. Thus it is often helpful to view the code translations and perhaps insert the translated values in a data frame. Only a single table may be specified, but multiple variables within that table can be selected. Code translations are retrieved for each variable. If the environment variable NHANES_TABLE_BASE was set during startup, the value of this variable is used as the base URL instead of https://wwwn.cdc.gov (this allows the use of a local or alternative mirror of the CDC documentation).

Examples

# \donttest{
## May fail if CDC website is unavailable
try({
    nhanesTranslate('DEMO_B', c('DMDBORN','DMDCITZN')) |> print()
    nhanesTranslate('BPX_F', 'BPACSZ', details = TRUE) |> print()
    nhanesTranslate('BPX_F', 'BPACSZ', data = nhanes('BPX_F')) |> str()
    trans_demo = nhanesTranslate('DEMO_B')
    length(trans_demo)
})
#> $DMDBORN
#>   Code.or.Value                      Value.Description
#> 1             1 Born in 50 US States or Washington, DC
#> 2             2                         Born in Mexico
#> 3             3                         Born Elsewhere
#> 4             7                                Refused
#> 5             9                             Don't know
#> 6             .                                Missing
#> 
#> $DMDCITZN
#>   Code.or.Value                  Value.Description
#> 1             1 Citizen by birth or naturalization
#> 2             2            Not a citizen of the US
#> 3             7                            Refused
#> 4             9                         Don't know
#> 5             .                            Missing
#> 
#> $BPACSZ
#>   Code.or.Value Value.Description Count Cumulative Skip.to.Item
#> 1             1     Infant (6X12)     3          3           NA
#> 2             2      Child (9X17)   432        435           NA
#> 3             3     Adult (12X22)  2470       2905           NA
#> 4             4     Large (15X32)  3799       6704           NA
#> 5             5     Thigh (18X35)  1127       7831           NA
#> 6             .           Missing  2422      10253           NA
#> 
#> Translated columns: BPACSZ
#> 'data.frame':	10253 obs. of  27 variables:
#>  $ SEQN    : num  51624 51625 51626 51627 51628 ...
#>  $ PEASCST1: Factor w/ 3 levels "Complete","Partial",..: 1 1 1 1 1 1 1 1 1 1 ...
#>  $ PEASCTM1: num  583 278 689 699 1098 ...
#>  $ PEASCCT1: Factor w/ 9 levels "SP refusal","No time",..: NA NA NA NA NA NA NA NA NA NA ...
#>  $ BPXCHR  : num  NA 92 NA NA NA NA NA 112 NA NA ...
#>  $ BPQ150A : Factor w/ 2 levels "Yes","No": 2 NA 1 2 1 2 2 NA 2 2 ...
#>  $ BPQ150B : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPQ150C : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPQ150D : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPAARM  : Factor w/ 2 levels "Right","Left": 1 NA 1 1 1 1 1 NA 1 1 ...
#>  $ BPACSZ  : Factor w/ 5 levels "Infant (6X12)",..: 4 NA 3 3 5 4 4 NA 2 4 ...
#>  $ BPXPLS  : num  70 NA 68 68 72 72 86 NA 70 88 ...
#>  $ BPXPULS : Factor w/ 2 levels "Regular","Irregular": 1 1 1 1 1 1 1 1 1 1 ...
#>  $ BPXPTY  : Factor w/ 2 levels "Radial","Brachial": 1 NA 1 1 1 1 1 NA 1 1 ...
#>  $ BPXML1  : num  150 NA 140 120 170 140 140 NA 130 160 ...
#>  $ BPXSY1  : num  114 NA 112 92 154 102 118 NA 106 142 ...
#>  $ BPXDI1  : num  88 NA 62 36 70 50 82 NA 60 62 ...
#>  $ BPAEN1  : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPXSY2  : num  114 NA 114 94 150 104 108 NA 106 140 ...
#>  $ BPXDI2  : num  88 NA 60 44 68 48 74 NA 50 46 ...
#>  $ BPAEN2  : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPXSY3  : num  112 NA 104 92 150 104 116 NA 110 138 ...
#>  $ BPXDI3  : num  82 NA 58 38 68 50 76 NA 56 40 ...
#>  $ BPAEN3  : Factor w/ 2 levels "Yes","No": 2 NA 2 2 2 2 2 NA 2 2 ...
#>  $ BPXSY4  : num  NA NA NA NA NA NA NA NA NA NA ...
#>  $ BPXDI4  : num  NA NA NA NA NA NA NA NA NA NA ...
#>  $ BPAEN4  : Factor w/ 2 levels "Yes","No": NA NA NA NA NA NA NA NA NA NA ...
#> [1] 36
# }