-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate.r
58 lines (47 loc) · 2.76 KB
/
aggregate.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
library(dplyr)
library(tidyverse)
#Read data from all three .csv files
white <- read.csv("/Users/hritikasingh/Desktop/white.csv")
black <- read.csv("/Users/hritikasingh/Desktop/black.csv")
latino <- read.csv("/Users/hritikasingh/Desktop/latino.csv")
#Filter the data in each dataset to ONLY include the 'Both Sexes' row and first 7 columns.
white_filtered <- white%>%
select(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41., X, X.1, X.2, X.3, X.4, X.5, X.6)%>%
filter(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41. == 'BOTH SEXES')
white_filtered <- white_filtered%>%
rename(Sex = Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41.,
Demographic = X,
W_Total_Population = X.1,
W_Total_Citizen_Population = X.2,
W_Reported_Registered_Number = X.3,
W_Reported_Registered_Percent = X.4,
W_Reported_Not_Registered_Number = X.5,
W_Reported_Not_Registered_Percent = X.6)
black_filtered <- black%>%
select(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41., X, X.1, X.2, X.3, X.4, X.5, X.6)%>%
filter(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41. == 'BOTH SEXES')
black_filtered <- black_filtered%>%
rename(Sex = Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41.,
Demographic = X,
B_Total_Population = X.1,
B_Total_Citizen_Population = X.2,
B_Reported_Registered_Number = X.3,
B_Reported_Registered_Percent = X.4,
B_Reported_Not_Registered_Number = X.5,
B_Reported_Not_Registered_Percent = X.6)
latino_filtered <- latino%>%
select(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41., X, X.1, X.2, X.3, X.4, X.5, X.6)%>%
filter(Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41. == 'BOTH SEXES')
latino_filtered <- latino_filtered%>%
rename(Sex = Table.with.row.headers.in.columns.A.and.B..and.column.headers.in.rows.5.through.7.and.rows.39.to.41.,
Demographic = X,
L_Total_Population = X.1,
L_Total_Citizen_Population = X.2,
L_Reported_Registered_Number = X.3,
L_Reported_Registered_Percent = X.4,
L_Reported_Not_Registered_Number = X.5,
L_Reported_Not_Registered_Percent = X.6)
#Join all three tables into one master table, comparing all three tables side by side
tab <- merge(x=white_filtered, y=black_filtered, by="Demographic")
all_data <- merge(x=tab,y=latino_filtered, by="Demographic")
view(all_data)