diff options
Diffstat (limited to 'R Scripts/data-prep.R')
| -rwxr-xr-x | R Scripts/data-prep.R | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/R Scripts/data-prep.R b/R Scripts/data-prep.R index ca2fdc2..a6c31e6 100755 --- a/R Scripts/data-prep.R +++ b/R Scripts/data-prep.R @@ -86,15 +86,30 @@ for (i in 1:dim(a)[1]){ ir = a$ir_no[i] arr = arrests[arrests$ir_no==ir,] arr = arr[arr$sex_code_cd != 'X',] - if(dim(arr)[1]>0){ + if(dim(arr)[1]>0){# need to match rownames like districts? arrests$sex_code_cd[as.numeric(rownames(a[i,]))] = names(which.max(table(arr$sex_code_cd))) } } arrests$sex_code_cd[arrests$sex_code_cd=='X'] = 'M' +##### residential districts +arrests$o_district[arrests$o_district=='31'] = '' +a = arrests[arrests$o_district=='' & arrests$o_city=='CHICAGO',] +for (i in 1:dim(a)[1]){ + if(i%%200==0) print(i) + ir = a$ir_no[i] + arr = arrests[arrests$ir_no==ir,] + arr = arr[arr$o_district != '',] + if(dim(arr)[1]>0){ + arrests$o_district[match(as.numeric(rownames(a[i,])),rownames(arrests))] = names(which.max(table(arr$o_district))) + } +} +arrests$o_district[arrests$o_district==''] = 0 +# lcc_verts$district = arrests$o_district[match(lcc_verts$ir_no,arrests$ir2)] +# V(lcc)$district = arrests$o_district[match(lcc_verts$ir_no,arrests$ir2)] + #I need to add the "ir" for this to make sense when I "project" arrests$ir2 <- paste("ir", arrests$ir_no) - # save altered arrests data save(arrests,file='arrests.RData') @@ -180,7 +195,7 @@ murders = read.csv("murder-victims-13nov.csv", header=T) murders = murders[!is.na(murders$VICTIM_IR_NO),] murders = murders[murders$INJURY_DESCR=="SHOT",] murders = murders[match(unique(murders$VICTIM_IR_NO),murders$VICTIM_IR_NO),] -murders = murders[as.Date(murders$INJURY_DATE,format='%m/%d/%y')>=start_date,] +murders = murders[as.Date(murders$INJURY_DATE,format='%m/%d/%y')>start_date,] murders$ir2 = paste("ir", murders$VICTIM_IR_NO) # clear nonfatals that led to death |
