-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbridging_calc.R
34 lines (18 loc) · 1.13 KB
/
bridging_calc.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
# Calculation of Social Capital Bridging Values
#Load bridging calculation raw data
bridge_var <- read.csv("bridging_variables.csv")
# Get statistics for the variables by year
SoCI_bridge_stats <- bridge_var %>% group_by(year) %>%
summarize_at(vars(Religion:Civic), c("mean", "max", "min"), na.rm = TRUE)
SoCI_bridge_combo <- left_join(bridge_var, SoCI_bridge_stats, by = "year")
#normalization of yearly data
SoCI__bridge_norm <- SoCI_bridge_combo %>% mutate (religion_soc = (Religion - Religion_min)/(Religion_max - Religion_min),
civic_soc = (Civic -Civic_min)/(Civic_max - Civic_min),
affiliate_soc = (Affiliate - Affiliate_min)/(Affiliate_max - Affiliate_min))
SoCI_bridge_2 <- mutate(SoCI__bridge_norm, SoCI_bridge = ((religion_soc + civic_soc +
affiliate_soc)/3))
# Pull out final table with just fips, year and bridging number
SoCI_bridge_2010 <- select(SoCI_bridge_2, c(fips_n, year, SoCI_bridge))
View(SoCI_bridge_2010)
# write final csv
write.csv(SoCI_bridge_2010, file = "SoCI_bridge_2010.csv")