Skip to contents

Convert any FIPS codes to the FIPS of all the blockgroups that are among or within or containing those FIPS

Usage

fips_bgs_in_fips(fips)

Arguments

fips

vector of US FIPS codes, as character or numeric, with or without their leading zeroes, each with as many characters

Value

vector of blockgroup FIPS (or NA values) that may be much longer than the vector of fips passed to this function.

Details

This is a way to get a list of blockgroups, specified by state/county/tract or even block.

Takes a vector of one or more FIPS that could be State (2-digit), County (5-digit), Tract (11-digit), or blockgroup (12 digit), or even block (15-digit fips).

Returns unique vector of FIPS of all US blockgroups (including DC and Puerto Rico) that contain any specified blocks, are equal to any specified blockgroup fips, or are contained within any provided tract/county/state FIPS.

See also

Examples


  # all blockgroups in one state
  fips_counties_from_state_abbrev("DE")
#> [1] "10001" "10003" "10005"
  fips_bgs_in_fips( fips_counties_from_state_abbrev("DE") )
#>   [1] "100010401001" "100010401002" "100010401003" "100010401004" "100010402011"
#>   [6] "100010402012" "100010402013" "100010402031" "100010402032" "100010402033"
#>  [11] "100010402041" "100010402042" "100010402043" "100010402051" "100010402052"
#>  [16] "100010402053" "100010402061" "100010405011" "100010405012" "100010405013"
#>  [21] "100010405021" "100010405022" "100010407001" "100010407002" "100010407003"
#>  [26] "100010409001" "100010409002" "100010410001" "100010410002" "100010410003"
#>  [31] "100010411011" "100010411012" "100010411013" "100010412001" "100010412002"
#>  [36] "100010412003" "100010413001" "100010413002" "100010414001" "100010414002"
#>  [41] "100010415001" "100010415002" "100010416001" "100010417011" "100010417012"
#>  [46] "100010417013" "100010417014" "100010417021" "100010417022" "100010418021"
#>  [51] "100010418022" "100010418023" "100010418031" "100010418032" "100010418041"
#>  [56] "100010418042" "100010418043" "100010419001" "100010419002" "100010419003"
#>  [61] "100010420001" "100010420002" "100010421001" "100010421002" "100010422031"
#>  [66] "100010422032" "100010422033" "100010422041" "100010422042" "100010422051"
#>  [71] "100010422052" "100010422061" "100010422062" "100010422071" "100010422081"
#>  [76] "100010422082" "100010425001" "100010425002" "100010425003" "100010428011"
#>  [81] "100010428021" "100010428022" "100010428023" "100010429001" "100010429002"
#>  [86] "100010430001" "100010430002" "100010430003" "100010431001" "100010431002"
#>  [91] "100010432021" "100010432022" "100010432023" "100010432024" "100010433001"
#>  [96] "100010433002" "100010433003" "100010434001" "100010434002" "100010434003"
#> [101] "100019800001" "100019900000" "100030002001" "100030002002" "100030002003"
#> [106] "100030002004" "100030002005" "100030002006" "100030003001" "100030003002"
#> [111] "100030003003" "100030004001" "100030004002" "100030004003" "100030005001"
#> [116] "100030005002" "100030005003" "100030005004" "100030006011" "100030006012"
#> [121] "100030006013" "100030006021" "100030006022" "100030006023" "100030009001"
#> [126] "100030009002" "100030009003" "100030011001" "100030011002" "100030011003"
#> [131] "100030012001" "100030012002" "100030013001" "100030013002" "100030013003"
#> [136] "100030013004" "100030014001" "100030014002" "100030015001" "100030015002"
#> [141] "100030016001" "100030016002" "100030016003" "100030019021" "100030019022"
#> [146] "100030021001" "100030021002" "100030022001" "100030022002" "100030022003"
#> [151] "100030023001" "100030023002" "100030023003" "100030024001" "100030024002"
#> [156] "100030024003" "100030024004" "100030025001" "100030025002" "100030025003"
#> [161] "100030026001" "100030026002" "100030026003" "100030026004" "100030027001"
#> [166] "100030027002" "100030028001" "100030028002" "100030029001" "100030029002"
#> [171] "100030029003" "100030029004" "100030030021" "100030030022" "100030101041"
#> [176] "100030101042" "100030101051" "100030101052" "100030101061" "100030101062"
#> [181] "100030101063" "100030102001" "100030102002" "100030103001" "100030103002"
#> [186] "100030103003" "100030104001" "100030104002" "100030104003" "100030104004"
#> [191] "100030105021" "100030105022" "100030105023" "100030105024" "100030105025"
#> [196] "100030107031" "100030107032" "100030107041" "100030107042" "100030107043"
#> [201] "100030108001" "100030108002" "100030108003" "100030109001" "100030109002"
#> [206] "100030109003" "100030110001" "100030110002" "100030110003" "100030111001"
#> [211] "100030112011" "100030112012" "100030112021" "100030112022" "100030112031"
#> [216] "100030112032" "100030112033" "100030112041" "100030112042" "100030112051"
#> [221] "100030112052" "100030112061" "100030112062" "100030113001" "100030113002"
#> [226] "100030114001" "100030114002" "100030114003" "100030115001" "100030115002"
#> [231] "100030115003" "100030116001" "100030116002" "100030117001" "100030117002"
#> [236] "100030117003" "100030117004" "100030118001" "100030118002" "100030118003"
#> [241] "100030118004" "100030119001" "100030119002" "100030119003" "100030120001"
#> [246] "100030120002" "100030120003" "100030121001" "100030121002" "100030121003"
#> [251] "100030122001" "100030122002" "100030122003" "100030122004" "100030123001"
#> [256] "100030123002" "100030124001" "100030124002" "100030124003" "100030124004"
#> [261] "100030125001" "100030125002" "100030125003" "100030125004" "100030125005"
#> [266] "100030125006" "100030126001" "100030126002" "100030126003" "100030127001"
#> [271] "100030127002" "100030127003" "100030127004" "100030127005" "100030129001"
#> [276] "100030129002" "100030129003" "100030130001" "100030130002" "100030131001"
#> [281] "100030131002" "100030131003" "100030132001" "100030132002" "100030132003"
#> [286] "100030133001" "100030133002" "100030134001" "100030134002" "100030134003"
#> [291] "100030135011" "100030135012" "100030135013" "100030135014" "100030135015"
#> [296] "100030135051" "100030135052" "100030135061" "100030135062" "100030135063"
#> [301] "100030135071" "100030135081" "100030135082" "100030135083" "100030136041"
#> [306] "100030136042" "100030136043" "100030136071" "100030136072" "100030136073"
#> [311] "100030136074" "100030136081" "100030136082" "100030136101" "100030136102"
#> [316] "100030136103" "100030136104" "100030136111" "100030136112" "100030136113"
#> [321] "100030136114" "100030136121" "100030136122" "100030136123" "100030136131"
#> [326] "100030136132" "100030136133" "100030136141" "100030136142" "100030136151"
#> [331] "100030136152" "100030136153" "100030137001" "100030137002" "100030137003"
#> [336] "100030138001" "100030138002" "100030138003" "100030139011" "100030139012"
#> [341] "100030139013" "100030139031" "100030139032" "100030139033" "100030139051"
#> [346] "100030139052" "100030139053" "100030139061" "100030139062" "100030139063"
#> [351] "100030140001" "100030140002" "100030140003" "100030140004" "100030141001"
#> [356] "100030141002" "100030141003" "100030142001" "100030143011" "100030143021"
#> [361] "100030143022" "100030143023" "100030144021" "100030144022" "100030144031"
#> [366] "100030144032" "100030144033" "100030144041" "100030144042" "100030145011"
#> [371] "100030145021" "100030145022" "100030147021" "100030147031" "100030147032"
#> [376] "100030147033" "100030147034" "100030147051" "100030147052" "100030147053"
#> [381] "100030147061" "100030147062" "100030148031" "100030148032" "100030148033"
#> [386] "100030148081" "100030148082" "100030148083" "100030148084" "100030148091"
#> [391] "100030148092" "100030148093" "100030148094" "100030148095" "100030148101"
#> [396] "100030148102" "100030148103" "100030148111" "100030148112" "100030148113"
#> [401] "100030148121" "100030148122" "100030148123" "100030148131" "100030148132"
#> [406] "100030148133" "100030148141" "100030148142" "100030149031" "100030149032"
#> [411] "100030149033" "100030149034" "100030149035" "100030149036" "100030149041"
#> [416] "100030149042" "100030149061" "100030149062" "100030149063" "100030149071"
#> [421] "100030149072" "100030149073" "100030149081" "100030149082" "100030149091"
#> [426] "100030149092" "100030149093" "100030149094" "100030150001" "100030150002"
#> [431] "100030150003" "100030150004" "100030150005" "100030151001" "100030151002"
#> [436] "100030152001" "100030152002" "100030152003" "100030152004" "100030152005"
#> [441] "100030154001" "100030154002" "100030155021" "100030155022" "100030156001"
#> [446] "100030156002" "100030158021" "100030158022" "100030159001" "100030159002"
#> [451] "100030159003" "100030160001" "100030160002" "100030161001" "100030161002"
#> [456] "100030162001" "100030162002" "100030162003" "100030163011" "100030163012"
#> [461] "100030163013" "100030163014" "100030163061" "100030163062" "100030163063"
#> [466] "100030163071" "100030163081" "100030163082" "100030163091" "100030163092"
#> [471] "100030164011" "100030164012" "100030164013" "100030164014" "100030164041"
#> [476] "100030164042" "100030164043" "100030166081" "100030166082" "100030166091"
#> [481] "100030166092" "100030166093" "100030166101" "100030166102" "100030166103"
#> [486] "100030166104" "100030166111" "100030166112" "100030166113" "100030166121"
#> [491] "100030166122" "100030166123" "100030166131" "100030166132" "100030166133"
#> [496] "100030166134" "100030166141" "100030166142" "100030166143" "100030168051"
#> [501] "100030168061" "100030168062" "100030168063" "100030168071" "100030168081"
#> [506] "100030168082" "100030168083" "100030168084" "100030168085" "100030169011"
#> [511] "100030169012" "100030169041" "100039801001" "100039901000" "100050501011"
#> [516] "100050501012" "100050501013" "100050501031" "100050501032" "100050501033"
#> [521] "100050501034" "100050501041" "100050501042" "100050501043" "100050501051"
#> [526] "100050501052" "100050501053" "100050501054" "100050502001" "100050502002"
#> [531] "100050502003" "100050503021" "100050503022" "100050503023" "100050503031"
#> [536] "100050503032" "100050503041" "100050503042" "100050503043" "100050504011"
#> [541] "100050504012" "100050504031" "100050504032" "100050504051" "100050504052"
#> [546] "100050504061" "100050504062" "100050504063" "100050504064" "100050504071"
#> [551] "100050504072" "100050504073" "100050504081" "100050504082" "100050504083"
#> [556] "100050505011" "100050505012" "100050505013" "100050505031" "100050505032"
#> [561] "100050505033" "100050505051" "100050505061" "100050505062" "100050506011"
#> [566] "100050506012" "100050506013" "100050506031" "100050506032" "100050506041"
#> [571] "100050506042" "100050506043" "100050507011" "100050507012" "100050507013"
#> [576] "100050507031" "100050507032" "100050507061" "100050507062" "100050507063"
#> [581] "100050507071" "100050507072" "100050507081" "100050507091" "100050507092"
#> [586] "100050507101" "100050507102" "100050507111" "100050507112" "100050508011"
#> [591] "100050508012" "100050508013" "100050508041" "100050508042" "100050508051"
#> [596] "100050508052" "100050508061" "100050508062" "100050508063" "100050508064"
#> [601] "100050508071" "100050508072" "100050508081" "100050508082" "100050508083"
#> [606] "100050509031" "100050509032" "100050509041" "100050509042" "100050509051"
#> [611] "100050509052" "100050509053" "100050509054" "100050510081" "100050510082"
#> [616] "100050510083" "100050510091" "100050510092" "100050510093" "100050510101"
#> [621] "100050510102" "100050510103" "100050510111" "100050510112" "100050510113"
#> [626] "100050510121" "100050510122" "100050510131" "100050510132" "100050510141"
#> [631] "100050510142" "100050510151" "100050510152" "100050510161" "100050510162"
#> [636] "100050510171" "100050510172" "100050510173" "100050511011" "100050511012"
#> [641] "100050511013" "100050511021" "100050511022" "100050511023" "100050511031"
#> [646] "100050511032" "100050511033" "100050512011" "100050512012" "100050512021"
#> [651] "100050512022" "100050512031" "100050512032" "100050512033" "100050512034"
#> [656] "100050512041" "100050512042" "100050512043" "100050512044" "100050512051"
#> [661] "100050512052" "100050513021" "100050513022" "100050513023" "100050513071"
#> [666] "100050513081" "100050513082" "100050513083" "100050513091" "100050513092"
#> [671] "100050513101" "100050513111" "100050513112" "100050513121" "100050513122"
#> [676] "100050513131" "100050513132" "100050513133" "100050513141" "100050513142"
#> [681] "100050514001" "100050514002" "100050514003" "100050515011" "100050515012"
#> [686] "100050515021" "100050515022" "100050515023" "100050517011" "100050517012"
#> [691] "100050517013" "100050517021" "100050517022" "100050517023" "100050518011"
#> [696] "100050518012" "100050518013" "100050518014" "100050518021" "100050518022"
#> [701] "100050518023" "100050519001" "100050519002" "100050519003" "100059800001"
#> [706] "100059900000"

  blockgroupstats[,.N,by=substr(bgfips,1,2)]
#>     substr     N
#>     <char> <int>
#>  1:     01  3925
#>  2:     02   504
#>  3:     04  4773
#>  4:     05  2294
#>  5:     06 25607
#>  6:     08  4058
#>  7:     09  2717
#>  8:     10   706
#>  9:     11   571
#> 10:     12 13388
#> 11:     13  7446
#> 12:     15  1083
#> 13:     16  1284
#> 14:     17  9898
#> 15:     18  5290
#> 16:     19  2703
#> 17:     20  2461
#> 18:     21  3581
#> 19:     22  4294
#> 20:     23  1184
#> 21:     24  4079
#> 22:     25  5116
#> 23:     26  8386
#> 24:     27  4706
#> 25:     28  2445
#> 26:     29  5031
#> 27:     30   900
#> 28:     31  1648
#> 29:     32  1963
#> 30:     33   997
#> 31:     34  6599
#> 32:     35  1614
#> 33:     36 16070
#> 34:     37  7111
#> 35:     38   632
#> 36:     39  9472
#> 37:     40  3374
#> 38:     41  2970
#> 39:     42 10173
#> 40:     44   792
#> 41:     45  3408
#> 42:     46   694
#> 43:     47  4562
#> 44:     48 18638
#> 45:     49  2020
#> 46:     50   552
#> 47:     51  5963
#> 48:     53  5311
#> 49:     54  1639
#> 50:     55  4692
#> 51:     56   457
#> 52:     72  2555
#>     substr     N
  length(fips_bgs_in_fips("72"))
#> [1] 2555

  # all blockgroups in this one county
  fips_bgs_in_fips(30001)
#>  [1] "300010001001" "300010001002" "300010002001" "300010002002" "300010002003"
#>  [6] "300010002004" "300010003001" "300010003002" "300010003003" "300010003004"
  fips_bgs_in_fips("30001")
#>  [1] "300010001001" "300010001002" "300010002001" "300010002002" "300010002003"
#>  [6] "300010002004" "300010003001" "300010003002" "300010003003" "300010003004"
  fips_bgs_in_fips(fips_counties_from_statename("Rhode Island")[1])
#>  [1] "440010301001" "440010301002" "440010301003" "440010301004" "440010302001"
#>  [6] "440010302002" "440010302003" "440010303001" "440010303002" "440010303003"
#> [11] "440010304001" "440010304002" "440010304003" "440010305001" "440010305002"
#> [16] "440010305003" "440010306011" "440010306012" "440010306013" "440010306021"
#> [21] "440010306022" "440010306023" "440010306024" "440010307001" "440010307002"
#> [26] "440010307003" "440010307004" "440010308001" "440010308002" "440010308003"
#> [31] "440010309011" "440010309012" "440010309013" "440010309021" "440010309022"
#> [36] "440010309023" "440010309024"

  # all blockgroups that contain any of these 6 blocks (i.e., just one bg)
  ## dataload_from_pins("blockid2fips") # very large file to avoid using unless essential
  ## x = blockid2fips$blockfips[1:6] 
  x = c("010010201001000", "010010201001001", "010010201001002",
   "010010201001003", "010010201001004", "010010201001005")
  fips_bgs_in_fips(x)
#> [1] "010010201001"

  # 2 counties
  fips_bgs_in_fips(c(36009,36011))
#>   [1] "360099400001" "360099400002" "360099402001" "360099403011" "360099403012"
#>   [6] "360099403013" "360099403021" "360099403022" "360099403023" "360099601001"
#>  [11] "360099601002" "360099601003" "360099602001" "360099602002" "360099602003"
#>  [16] "360099602004" "360099603001" "360099603002" "360099603003" "360099603004"
#>  [21] "360099604001" "360099604002" "360099604003" "360099604004" "360099605001"
#>  [26] "360099605002" "360099605003" "360099605004" "360099605005" "360099606001"
#>  [31] "360099606002" "360099606003" "360099606004" "360099607031" "360099607032"
#>  [36] "360099607041" "360099607042" "360099608001" "360099608002" "360099608003"
#>  [41] "360099608004" "360099610001" "360099610002" "360099610003" "360099610004"
#>  [46] "360099611001" "360099611002" "360099611003" "360099611004" "360099612001"
#>  [51] "360099612002" "360099612003" "360099612004" "360099613011" "360099613012"
#>  [56] "360099613021" "360099613022" "360099614001" "360099614002" "360099614003"
#>  [61] "360099614004" "360099615001" "360099615002" "360099616001" "360099616002"
#>  [66] "360099616003" "360099616004" "360099617001" "360099617002" "360099617003"
#>  [71] "360099618001" "360099618002" "360099618003" "360099618004" "360099618005"
#>  [76] "360099618006" "360099622001" "360099622002" "360099622003" "360099622004"
#>  [81] "360110401011" "360110401012" "360110401021" "360110401022" "360110401023"
#>  [86] "360110402011" "360110402012" "360110402013" "360110402021" "360110402022"
#>  [91] "360110403001" "360110403002" "360110403003" "360110403004" "360110404001"
#>  [96] "360110404002" "360110404003" "360110405001" "360110405002" "360110405003"
#> [101] "360110406001" "360110406002" "360110406003" "360110407001" "360110407002"
#> [106] "360110407003" "360110407004" "360110408001" "360110408002" "360110408003"
#> [111] "360110408004" "360110409001" "360110409002" "360110409003" "360110409004"
#> [116] "360110410011" "360110410012" "360110410013" "360110410021" "360110410022"
#> [121] "360110411011" "360110411012" "360110411013" "360110411021" "360110411022"
#> [126] "360110412011" "360110412012" "360110412021" "360110412022" "360110412023"
#> [131] "360110413001" "360110413002" "360110413003" "360110413004" "360110413005"
#> [136] "360110414001" "360110414002" "360110414003" "360110414004" "360110415001"
#> [141] "360110415002" "360110415003" "360110415004" "360110416001" "360110416002"
#> [146] "360110416003" "360110417001" "360110417002" "360110417003" "360110417004"
#> [151] "360110417005" "360110418001" "360110418002" "360110418003" "360110418004"
#> [156] "360110418005" "360110421001" "360110421002" "360110421003" "360119902000"