Skip to contents

Used by naics_find()

Usage

naics2children(codes, allcodes = EJAM::NAICS, quiet = FALSE)

Arguments

codes

vector of numerical or character

allcodes

Optional (already loaded with package) - dataset with all the codes

quiet

whether to avoid printing results to console

Value

vector of codes and their names

Details

  • Starts with shortest (highest level) codes. Since tied for nchar, these branches have zero overlap, so do each.

  • For each of those, get its children = all rows where parentcode == substr(allcodes, 1, nchar(parentcode))

  • Put together list of all codes we want to include so far.

  • For the next longest set of codes in original list of codes, do same thing.

  • continue until done for 5-digit ones to get 6-digit children.

  • Take the unique(allthat)

table(nchar(as.character(NAICS)))

2 3 4 5 6

17 99 311 709 1057

See also

naics_find() NAICS

Examples

  naics2children(211)
#> 
#> 211 - Oil and Gas Extraction 
#> 2111 - Oil and Gas Extraction 
#> 21112 - Crude Petroleum Extraction  
#> 211120 - Crude Petroleum Extraction  
#> 21113 - Natural Gas Extraction  
#> 211130 - Natural Gas Extraction  
  naics_find(211, exactnumber=TRUE)
#> Error in naics_find(211, exactnumber = TRUE): could not find function "naics_find"
  naics_find(211, exactnumber=TRUE, add_children = TRUE)
#> Error in naics_find(211, exactnumber = TRUE, add_children = TRUE): could not find function "naics_find"
  NAICS[211][1:3] # wrong
#> 236117 - New Housing For-Sale Builders                                   <NA> 
#>                                 236117                                     NA 
#>                                   <NA> 
#>                                     NA 
  NAICS[NAICS == 211]
#> 211 - Oil and Gas Extraction 
#>                          211 
  NAICS["211 - Oil and Gas Extraction"]
#> 211 - Oil and Gas Extraction 
#>                          211