andrea.nieves7 2 lat temu
rodzic
commit
d43baf974e
1 zmienionych plików z 51 dodań i 0 usunięć
  1. 51
    0
      R.R

+ 51
- 0
R.R Wyświetl plik

@@ -0,0 +1,51 @@
1
+library(tidycensus)
2
+library(tidyverse)
3
+
4
+tableYear = 2020
5
+
6
+#log on with API
7
+census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
8
+
9
+#load variables
10
+variables = load_variables(2020,"acs5/profile")
11
+codes = variables$name
12
+label0 = variables$label
13
+
14
+#view variables
15
+#varTable = table(variables$concept)
16
+#write.table(varTable, file = "cat.txt", sep = ",", quote = FALSE, row.names = F)
17
+
18
+#pull all tables with every variable
19
+  
20
+test = get_acs(geography = "county",
21
+               state = "PR",
22
+               year = tableYear,
23
+               variables = codes)
24
+
25
+#add label column
26
+#create empty vector 
27
+labelCol = c()
28
+
29
+#amount of GEOIDS
30
+for (x in 1:78){
31
+  labelCol = c(labelCol, label0)
32
+}
33
+
34
+#combine test and cols
35
+test["label"] = labelCol
36
+
37
+#rearrange cols
38
+test = test[c("NAME","label","variable","estimate","moe","GEOID")]
39
+
40
+GEOIDS = table(test$GEOID)
41
+
42
+#omit NA rows
43
+noNA = na.omit(test)
44
+
45
+DP02table = noNA %>% filter(startsWith(variable,"DP02"))
46
+
47
+DP03table = noNA %>% filter(startsWith(variable,"DP03"))
48
+
49
+DP04table = noNA %>% filter(startsWith(variable,"DP04"))
50
+
51
+DP05table = noNA %>% filter(startsWith(variable,"DP05"))