JJWaffle
JJWaffle

Reputation: 1

Trouble Reading Census Data into R (read.delim, read.table)

I am trying to read in Census regional data from the text file at (https://www2.census.gov/geo/docs/reference/ua/ua_list_all.txt). But the delimit function is not separating the columns apart. I've tried setting sep to default, " ", "\t", but the results are either errors or everything crammed into a single column.

Here is the code I'm using:

read.delim("https://www2.census.gov/geo/docs/reference/ua/ua_list_all.txt", sep = "")

This is the error I receive:

Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

This is the output when I set sep = "\t":

UACE......NAME...................................................................POP............HU...........AREALAND..AREALANDSQMI..........AREAWATER.AREAWATERSQMI........POPDEN..LSADC
<chr>
00037 Abbeville, LA 19824 8460 29222871 11.28 300497 0.12 1757.0 76
00064 Abbeville, SC 5243 2578 11315197 4.37 19786 0.01 1200.1 76
00091 Abbotsford, WI 3966 1616 5363441 2.07 13221 0.01 1915.2 76
00118 Aberdeen, MS 4666 2050 7416616 2.86 52732 0.02 1629.4 76
00145 Aberdeen, SD 25977 12114 33002447 12.74 247597 0.10 2038.6 76
00172 Aberdeen, WA 29856 13139 39997951 15.44 1929689 0.75 1933.3 76
00199 Aberdeen--Bel Air South--Bel Air North, MD 213751 83721 339626464 131.13 9825290 3.79 1630.1 75
00226 Abernathy, TX 2785 1124 3051109 1.18 12572 0.00 2364.1 76
00253 Abilene, KS 7054 3238 8773263 3.39 1877 0.00 2082.4 76
00280 Abilene, TX 110421 46732 141756054 54.73 988193 0.38 2017.5 75
00334 Abingdon, IL 3389 1483 3731303 1.44 0 0.00 2352.4 76
00388 Ada, OH 5945 1906 4769036 1.84 0 0.00 3228.6 76
00415 Ada, OK 17400 8086 30913906 11.94 89140 0.03 1457.8 76
00450 Adams, NY 2542 1100 5107296 1.97 13914 0.01 1289.1 76
00469 Adel, GA 6986 2990 15634050 6.04 204861 0.08 1157.3 76
00496 Adel, IA 3170 1317 4624127 1.79 0 0.00 1775.5 76
...
1-16 of 3,601 rows

Upvotes: 0

Views: 90

Answers (1)

tester
tester

Reputation: 1692

I'd propose a different solution, since there seems to be a strange delimiter used for the .txt file: How about you download the .xls file in the same folder and use that? The link to 'ua_list_all.xls' is here: https://www2.census.gov/geo/docs/reference/ua/ See code below:

library(readxl)
test <- readxl::read_excel(path = 'ua_list_all.xls')

Upvotes: 0

Related Questions