Skip to contents

Find industry names and codes by searching for queried code(s) or text

Usage

naics_from_any(
  query,
  children = FALSE,
  ignore.case = TRUE,
  fixed = FALSE,
  website_scrape = FALSE,
  website_url = FALSE
)

Arguments

query

query string(s) and/or number(s), vector of NAICS codes or industry names or any regular expression or partial words

children

logical, if TRUE, also return all the subcategories - where NAICS starts with the same digits

ignore.case

see grepl()

fixed

should it be an exact match? see grepl()

website_scrape

whether to scrape info from the NAICS website to return a table of codes and names that match (web query uses synonyms so gets more hits)

website_url

whether to return the URL of the webpage with info on the NAICS (web query uses synonyms so gets more hits)

Value

a subset of the naicstable data.table (not just the codes column)

Details

Finding the right NAICS/SIC and finding all the right sites is complicated. See discussion of latlon_from_naics().

Examples

# Also see vignettes for many more examples, and discussion.
  naics_categories()
#> Also see https://www.naics.com/search/ 
#>                                                                               [,1]
#> 11 - Agriculture, Forestry, Fishing and Hunting                                 11
#> 21 - Mining, Quarrying, and Oil and Gas Extraction                              21
#> 22 - Utilities                                                                  22
#> 23 - Construction                                                               23
#> 42 - Wholesale Trade                                                            42
#> 51 - Information                                                                51
#> 52 - Finance and Insurance                                                      52
#> 53 - Real Estate and Rental and Leasing                                         53
#> 54 - Professional, Scientific, and Technical Services                           54
#> 55 - Management of Companies and Enterprises                                    55
#> 56 - Administrative and Support and Waste Management and Remediation Services   56
#> 61 - Educational Services                                                       61
#> 62 - Health Care and Social Assistance                                          62
#> 71 - Arts, Entertainment, and Recreation                                        71
#> 72 - Accommodation and Food Services                                            72
#> 81 - Other Services (except Public Administration)                              81
#> 92 - Public Administration                                                      92
#> 31 - Manufacturing                                                              31
#> 32 - Manufacturing                                                              32
#> 33 - Manufacturing                                                              33
#> 44 - Retail Trade                                                               44
#> 45 - Retail Trade                                                               45
#> 48 - Transportation and Warehousing                                             48
#> 49 - Transportation and Warehousing                                             49
  
  naics_from_any("textile mills", children = FALSE)
#>     code     n2     n3     n4     n5     n6          name            num_name
#>    <num> <char> <char> <char> <char> <char>        <char>              <char>
#> 1:   313     31    313    313    313    313 Textile Mills 313 - Textile Mills
  naics_from_any("textile mills", children = TRUE)
#>       code     n2     n3     n4     n5     n6
#>      <num> <char> <char> <char> <char> <char>
#>  1:    313     31    313    313    313    313
#>  2:   3131     31    313   3131   3131   3131
#>  3:  31311     31    313   3131  31311  31311
#>  4: 313110     31    313   3131  31311 313110
#>  5:   3132     31    313   3132   3132   3132
#>  6:  31321     31    313   3132  31321  31321
#>  7: 313210     31    313   3132  31321 313210
#>  8:  31322     31    313   3132  31322  31322
#>  9: 313220     31    313   3132  31322 313220
#> 10:  31323     31    313   3132  31323  31323
#> 11: 313230     31    313   3132  31323 313230
#> 12:  31324     31    313   3132  31324  31324
#> 13: 313240     31    313   3132  31324 313240
#> 14:   3133     31    313   3133   3133   3133
#> 15:  31331     31    313   3133  31331  31331
#> 16: 313310     31    313   3133  31331 313310
#> 17:  31332     31    313   3133  31332  31332
#> 18: 313320     31    313   3133  31332 313320
#>                                                      name
#>                                                    <char>
#>  1:                                         Textile Mills
#>  2:                         Fiber, Yarn, and Thread Mills
#>  3:                         Fiber, Yarn, and Thread Mills
#>  4:                         Fiber, Yarn, and Thread Mills
#>  5:                                          Fabric Mills
#>  6:                               Broadwoven Fabric Mills
#>  7:                               Broadwoven Fabric Mills
#>  8:   Narrow Fabric Mills and Schiffli Machine Embroidery
#>  9:   Narrow Fabric Mills and Schiffli Machine Embroidery
#> 10:                                 Nonwoven Fabric Mills
#> 11:                                 Nonwoven Fabric Mills
#> 12:                                     Knit Fabric Mills
#> 13:                                     Knit Fabric Mills
#> 14: Textile and Fabric Finishing and Fabric Coating Mills
#> 15:                    Textile and Fabric Finishing Mills
#> 16:                    Textile and Fabric Finishing Mills
#> 17:                                  Fabric Coating Mills
#> 18:                                  Fabric Coating Mills
#>                                                         num_name
#>                                                           <char>
#>  1:                                          313 - Textile Mills
#>  2:                         3131 - Fiber, Yarn, and Thread Mills
#>  3:                        31311 - Fiber, Yarn, and Thread Mills
#>  4:                       313110 - Fiber, Yarn, and Thread Mills
#>  5:                                          3132 - Fabric Mills
#>  6:                              31321 - Broadwoven Fabric Mills
#>  7:                             313210 - Broadwoven Fabric Mills
#>  8:  31322 - Narrow Fabric Mills and Schiffli Machine Embroidery
#>  9: 313220 - Narrow Fabric Mills and Schiffli Machine Embroidery
#> 10:                                31323 - Nonwoven Fabric Mills
#> 11:                               313230 - Nonwoven Fabric Mills
#> 12:                                    31324 - Knit Fabric Mills
#> 13:                                   313240 - Knit Fabric Mills
#> 14: 3133 - Textile and Fabric Finishing and Fabric Coating Mills
#> 15:                   31331 - Textile and Fabric Finishing Mills
#> 16:                  313310 - Textile and Fabric Finishing Mills
#> 17:                                 31332 - Fabric Coating Mills
#> 18:                                313320 - Fabric Coating Mills

  frs_from_naics("textile mills", children = FALSE)
#>         lat       lon  REGISTRY_ID
#>       <num>     <num>       <char>
#> 1: 35.75407 -81.66109 110018721757
#> 2: 40.73562 -74.06953 110032399811
#>                                              PRIMARY_NAME          NAICS
#>                                                    <char>         <char>
#> 1: VISCOTEC AUTOMOTIVE PRODUCTS LIMITED LIABILITY COMPANY 000313, 313210
#> 2:                                       NYC TEXTILES INC         000313
#>                 SIC
#>              <char>
#> 1: 2221, 2299, 9999
#> 2:             2200
#>                                                                                                 PGM_SYS_ACRNMS
#>                                                                                                         <char>
#> 1: AIR:NC0000003701200180, AIRS/AFS:3702300180, EIS:16599711, NC-FITS:2505, NPDES:NCG170400, TSCA:TSCA10052078
#> 2:                                                                                             NJ-NJEMS:189589
  frs_from_naics("textile mills", children = TRUE)
#>           lat       lon  REGISTRY_ID                      PRIMARY_NAME
#>         <num>     <num>       <char>                            <char>
#>   1: 42.12030 -72.30787 110000308104                 TRELLEBORG MONSON
#>   2: 42.62707 -71.15672 110000309684                  SHAWSHEEN RUBBER
#>   3: 42.72361 -70.96296 110000309773                     HOOD COATINGS
#>   4: 42.70402 -71.14233 110000309871                JAYBIRD & MAIS INC
#>   5: 42.15941 -71.11289 110000310547       SIKA CORP SIKA SARNAFIL DIV
#>  ---                                                                  
#> 891: 40.59907 -74.69969 110071870812                      REBTEX, INC.
#> 892: 34.54770 -85.31120 110071871678                MOUNT VERNON MILLS
#> 893: 31.05099 -97.43662 110071871810                      BELTON BELCO
#> 894: 41.86364 -71.40141 110071872436                      COOLEY, INC.
#> 895: 34.96453 -80.04413 110071872455 WADE MANUFACTURING CO - WADESBORO
#>                                       NAICS        SIC
#>                                      <char>     <char>
#>   1:                         313320, 314999       2295
#>   2: 313320, 322220, 322222, 326299, 339920 2295, 3069
#>   3:                         313320, 322222       2295
#>   4:                                 313320       2295
#>   5:                 313320, 326113, 326199       3079
#>  ---                                                  
#> 891:                                 313310           
#> 892:                                 313210           
#> 893:                                 313210           
#> 894:                                 313320           
#> 895:                                 313210           
#>                                                                                                                                                                    PGM_SYS_ACRNMS
#>                                                                                                                                                                            <char>
#>   1:                                      AIR:MA0000002504200856, AIRS/AFS:2504200856, EIS:8389711, MA-EPICS:117970, NPDES:MANOE2000, RCRAINFO:MAR000511915, TRIS:01057LMNTNPALME
#>   2: AIR:MA0000002512100001, AIRS/AFS:2512100001, EIS:8388811, ICIS:3601430780, MA-EPICS:133315, NPDES:MANOE3023, OSHA-OIS:342903606, RCRAINFO:MAR000006486, TRIS:01810SHWSHANDOV
#>   3:                                                                               AIR:MA0000002512100102, AIRS/AFS:2512100102, EIS:5710211, MA-EPICS:53682, TRIS:01833HDCTN70SEA
#>   4:                                                                               AIR:MA0000002512100039, AIRS/AFS:2512100039, EIS:8155511, MA-EPICS:53621, TRIS:01843JYBRD360ME
#>   5:                                                                 AIRS/AFS:2511900605, EIS:8112311, ICIS:5414750, MA-EPICS:133600, RCRAINFO:MAD005286802, TRIS:02021SRNFL100DA
#>  ---                                                                                                                                                                             
#> 891:                                                                                                                                                                  EIS:7481211
#> 892:                                                                                                                                                                  EIS:3694611
#> 893:                                                                                                                                                                  EIS:2998511
#> 894:                                                                                                                                                                  EIS:4834411
#> 895:                                                                                                                                                                  EIS:7811011
  
  # \donttest{
  naics_from_any(naics_categories(3))[order(name),.(name,code)][1:10,]
#> Also see https://www.naics.com/search/ 
#>                                                                              name
#>                                                                            <char>
#>  1:                                                                 Accommodation
#>  2:                                           Administration of Economic Programs
#>  3:                              Administration of Environmental Quality Programs
#>  4: Administration of Housing Programs, Urban Planning, and Community Development
#>  5:                                     Administration of Human Resource Programs
#>  6:                                           Administrative and Support Services
#>  7:                                                            Air Transportation
#>  8:                                               Ambulatory Health Care Services
#>  9:                                Amusement, Gambling, and Recreation Industries
#> 10:                                             Animal Production and Aquaculture
#>      code
#>     <num>
#>  1:   721
#>  2:   926
#>  3:   924
#>  4:   925
#>  5:   923
#>  6:   561
#>  7:   481
#>  8:   621
#>  9:   713
#> 10:   112
  naics_from_any(naics_categories(3))[order(code),.(code,name)][1:10,]
#> Also see https://www.naics.com/search/ 
#>      code                                            name
#>     <num>                                          <char>
#>  1:   111                                 Crop Production
#>  2:   112               Animal Production and Aquaculture
#>  3:   113                            Forestry and Logging
#>  4:   114                   Fishing, Hunting and Trapping
#>  5:   115 Support Activities for Agriculture and Forestry
#>  6:   211                          Oil and Gas Extraction
#>  7:   212                     Mining (except Oil and Gas)
#>  8:   213                   Support Activities for Mining
#>  9:   221                                       Utilities
#> 10:   236                       Construction of Buildings
  naics_from_code(211)
#> Error in naics_from_code(211): could not find function "naics_from_code"
  naicstable[code==211,]
#>     code     n2     n3     n4     n5     n6                   name
#>    <num> <char> <char> <char> <char> <char>                 <char>
#> 1:   211     21    211    211    211    211 Oil and Gas Extraction
#>                        num_name
#>                          <char>
#> 1: 211 - Oil and Gas Extraction
  naics_subcodes_from_code(211)
#>      code     n2     n3     n4     n5     n6                        name
#>     <num> <char> <char> <char> <char> <char>                      <char>
#> 1:    211     21    211    211    211    211      Oil and Gas Extraction
#> 2:   2111     21    211   2111   2111   2111      Oil and Gas Extraction
#> 3:  21112     21    211   2111  21112  21112 Crude Petroleum Extraction 
#> 4: 211120     21    211   2111  21112 211120 Crude Petroleum Extraction 
#> 5:  21113     21    211   2111  21113  21113     Natural Gas Extraction 
#> 6: 211130     21    211   2111  21113 211130     Natural Gas Extraction 
#>                                num_name
#>                                  <char>
#> 1:         211 - Oil and Gas Extraction
#> 2:        2111 - Oil and Gas Extraction
#> 3:  21112 - Crude Petroleum Extraction 
#> 4: 211120 - Crude Petroleum Extraction 
#> 5:      21113 - Natural Gas Extraction 
#> 6:     211130 - Natural Gas Extraction 
  naics_from_code(211,  children = TRUE)
#> Error in naics_from_code(211, children = TRUE): could not find function "naics_from_code"
  naicstable[n3==211,]
#>      code     n2     n3     n4     n5     n6                        name
#>     <num> <char> <char> <char> <char> <char>                      <char>
#> 1:    211     21    211    211    211    211      Oil and Gas Extraction
#> 2:   2111     21    211   2111   2111   2111      Oil and Gas Extraction
#> 3:  21112     21    211   2111  21112  21112 Crude Petroleum Extraction 
#> 4: 211120     21    211   2111  21112 211120 Crude Petroleum Extraction 
#> 5:  21113     21    211   2111  21113  21113     Natural Gas Extraction 
#> 6: 211130     21    211   2111  21113 211130     Natural Gas Extraction 
#>                                num_name
#>                                  <char>
#> 1:         211 - Oil and Gas Extraction
#> 2:        2111 - Oil and Gas Extraction
#> 3:  21112 - Crude Petroleum Extraction 
#> 4: 211120 - Crude Petroleum Extraction 
#> 5:      21113 - Natural Gas Extraction 
#> 6:     211130 - Natural Gas Extraction 
  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 

 naics_from_any("plastics and rubber")[,.(name,code)]
#>                                          name  code
#>                                        <char> <num>
#> 1: Plastics and Rubber Products Manufacturing   326
 naics_from_any(326)
#>     code     n2     n3     n4     n5     n6
#>    <num> <char> <char> <char> <char> <char>
#> 1:   326     32    326    326    326    326
#>                                          name
#>                                        <char>
#> 1: Plastics and Rubber Products Manufacturing
#>                                            num_name
#>                                              <char>
#> 1: 326 - Plastics and Rubber Products Manufacturing
 naics_from_any(326, children = T)[,.(code,name)]
#>       code
#>      <num>
#>  1:    326
#>  2:   3261
#>  3:  32611
#>  4: 326111
#>  5: 326112
#>  6: 326113
#>  7:  32612
#>  8: 326121
#>  9: 326122
#> 10:  32613
#> 11: 326130
#> 12:  32614
#> 13: 326140
#> 14:  32615
#> 15: 326150
#> 16:  32616
#> 17: 326160
#> 18:  32619
#> 19: 326191
#> 20: 326199
#> 21:   3262
#> 22:  32621
#> 23: 326211
#> 24: 326212
#> 25:  32622
#> 26: 326220
#> 27:  32629
#> 28: 326291
#> 29: 326299
#>       code
#>                                                                            name
#>                                                                          <char>
#>  1:                                  Plastics and Rubber Products Manufacturing
#>  2:                                              Plastics Product Manufacturing
#>  3:   Plastics Packaging Materials and Unlaminated Film and Sheet Manufacturing
#>  4:                                        Plastics Bag and Pouch Manufacturing
#>  5:       Plastics Packaging Film and Sheet (including Laminated) Manufacturing
#>  6:        Unlaminated Plastics Film and Sheet (except Packaging) Manufacturing
#>  7:    Plastics Pipe, Pipe Fitting, and Unlaminated Profile Shape Manufacturing
#>  8:                            Unlaminated Plastics Profile Shape Manufacturing
#>  9:                                Plastics Pipe and Pipe Fitting Manufacturing
#> 10: Laminated Plastics Plate, Sheet (except Packaging), and Shape Manufacturing
#> 11: Laminated Plastics Plate, Sheet (except Packaging), and Shape Manufacturing
#> 12:                                      Polystyrene Foam Product Manufacturing
#> 13:                                      Polystyrene Foam Product Manufacturing
#> 14:          Urethane and Other Foam Product (except Polystyrene) Manufacturing
#> 15:          Urethane and Other Foam Product (except Polystyrene) Manufacturing
#> 16:                                               Plastics Bottle Manufacturing
#> 17:                                               Plastics Bottle Manufacturing
#> 18:                                        Other Plastics Product Manufacturing
#> 19:                                     Plastics Plumbing Fixture Manufacturing
#> 20:                                    All Other Plastics Product Manufacturing
#> 21:                                                Rubber Product Manufacturing
#> 22:                                                          Tire Manufacturing
#> 23:                                      Tire Manufacturing (except Retreading)
#> 24:                                                             Tire Retreading
#> 25:                         Rubber and Plastics Hoses and Belting Manufacturing
#> 26:                         Rubber and Plastics Hoses and Belting Manufacturing
#> 27:                                          Other Rubber Product Manufacturing
#> 28:                             Rubber Product Manufacturing for Mechanical Use
#> 29:                                      All Other Rubber Product Manufacturing
#>                                                                            name
 naics_from_any("plastics", children=T)[,unique(n3)]
#> [1] "326" "424" "325"
 naics_from_any("pig")
#>      code     n2     n3     n4     n5     n6
#>     <num> <char> <char> <char> <char> <char>
#> 1:   1122     11    112   1122   1122   1122
#> 2:  11221     11    112   1122  11221  11221
#> 3: 112210     11    112   1122  11221 112210
#> 4:  32513     32    325   3251  32513  32513
#> 5: 325130     32    325   3251  32513 325130
#>                                       name
#>                                     <char>
#> 1:                     Hog and Pig Farming
#> 2:                     Hog and Pig Farming
#> 3:                     Hog and Pig Farming
#> 4: Synthetic Dye and Pigment Manufacturing
#> 5: Synthetic Dye and Pigment Manufacturing
#>                                            num_name
#>                                              <char>
#> 1:                       1122 - Hog and Pig Farming
#> 2:                      11221 - Hog and Pig Farming
#> 3:                     112210 - Hog and Pig Farming
#> 4:  32513 - Synthetic Dye and Pigment Manufacturing
#> 5: 325130 - Synthetic Dye and Pigment Manufacturing
 naics_from_any("pig ") # space after g
#>      code     n2     n3     n4     n5     n6                name
#>     <num> <char> <char> <char> <char> <char>              <char>
#> 1:   1122     11    112   1122   1122   1122 Hog and Pig Farming
#> 2:  11221     11    112   1122  11221  11221 Hog and Pig Farming
#> 3: 112210     11    112   1122  11221 112210 Hog and Pig Farming
#>                        num_name
#>                          <char>
#> 1:   1122 - Hog and Pig Farming
#> 2:  11221 - Hog and Pig Farming
#> 3: 112210 - Hog and Pig Farming

 # naics_from_any("copper smelting")
 # naics_from_any("copper smelting", website_scrape=TRUE)
 # browseURL(naics_from_any("copper smelting", website_url=TRUE) )

 a = naics_from_any("plastics")
 b = naics_from_any("rubber")
 fintersect(a,b)[,.(name,code)] #  a AND b
#> Error in fintersect(a, b): could not find function "fintersect"
 funion(a,b)[,.(name,code)]     #  a OR  b
#> Error in funion(a, b): could not find function "funion"
 naics_subcodes_from_code(funion(a,b)[,code])[,.(name,code)]   #  plus children
#> Error in funion(a, b): could not find function "funion"
 naics_from_any(funion(a,b)[,code], children=T)[,.(name,code)] #  same
#> Error in funion(a, b): could not find function "funion"

 NROW(naics_from_any(325))
#> [1] 1
#[1] 1
 NROW(naics_from_any(325, children = T))
#> [1] 54
#[1] 54
 NROW(naics_from_any("chem"))
#> [1] 20
#[1] 20
 NROW(naics_from_any("chem", children = T))
#> [1] 113
#[1] 104
# }