-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCalCountyl2000.R
30 lines (26 loc) · 1.16 KB
/
CalCountyl2000.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
cty <- scan("http://www.medepi.net/data/calpop/calcounty.txt", what="")
calpop <- read.csv("http://www.medepi.net/data/calpop/CalCounties2000.txt",header=T)
for(i in 1:length(cty)){
calpop$County[calpop$County==i] <- cty[i]
}
calpop$Agecat <- cut(calpop$Age, c(0,20,45,65,100),
include.lowest = TRUE, right = FALSE)
calpop$AsianPI <- calpop$Asian + calpop$Pacific.Islander
calpop$AmerInd <- calpop$American.Indian
calpop$Latino <- calpop$Hispanic
calpop$AfrAmer <- calpop$Black
baindex <- calpop$County=="Alameda" |
calpop$County=="San Francisco"
bapop <- calpop[baindex,]
agelabs <- names(table(bapop$Agecat))
sexlabs <- c("Female", "Male")
racen <- c("White", "AfrAmer", "AsianPI", "Latino", "Multirace", "AmerInd")
ctylabs <- names(table(bapop$County))
bapop2 <- aggregate(bapop[,racen],
list(Agecat = bapop$Agecat,
Sex = bapop$Sex,
County = bapop$County), sum)
tmp <- as.matrix(cbind(bapop2[1:4,racen], bapop2[5:8,racen],
bapop2[9:12,racen], bapop2[13:16,racen]))
bapop3 <- array(tmp, c(4, 6, 2, 2))
dimnames(bapop3) <- list(agelabs, racen, sexlabs, ctylabs)