library(tidyverse) 
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
setwd("~/Documents/Rstudio DataSets ")
library(readr)

Preview data

CRIMEDATA <- read_csv("/Users/robertperez/Documents/Rstudio DataSets /R11456262_SL050.csv", col_names = TRUE)
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   Geo_FIPS = col_character(),
##   Geo_NAME = col_character(),
##   Geo_QNAME = col_character(),
##   Geo_NATION = col_character(),
##   Geo_STATE = col_integer(),
##   Geo_COUNTY = col_character(),
##   SE_T001_001 = col_integer()
## )
## See spec(...) for full column specifications.
head(CRIMEDATA)
## # A tibble: 6 x 21
##   Geo_FIPS           Geo_NAME                    Geo_QNAME Geo_NATION
##      <chr>              <chr>                        <chr>      <chr>
## 1    36001      Albany County      Albany County, New York       <NA>
## 2    36003    Allegany County    Allegany County, New York       <NA>
## 3    36007      Broome County      Broome County, New York       <NA>
## 4    36009 Cattaraugus County Cattaraugus County, New York       <NA>
## 5    36011      Cayuga County      Cayuga County, New York       <NA>
## 6    36013  Chautauqua County  Chautauqua County, New York       <NA>
## # ... with 17 more variables: Geo_STATE <int>, Geo_COUNTY <chr>,
## #   SE_T001_001 <int>, SE_T003_001 <dbl>, SE_T003_002 <dbl>,
## #   SE_T003_003 <dbl>, SE_T005_001 <dbl>, SE_T005_002 <dbl>,
## #   SE_T005_003 <dbl>, SE_T005_004 <dbl>, SE_T005_005 <dbl>,
## #   SE_T005_006 <dbl>, SE_T007_001 <dbl>, SE_T007_002 <dbl>,
## #   SE_T007_003 <dbl>, SE_T007_004 <dbl>, SE_T009_001 <dbl>
tail(CRIMEDATA)
## # A tibble: 6 x 21
##   Geo_FIPS                         Geo_NAME
##      <chr>                            <chr>
## 1    36115                Washington County
## 2    36117                     Wayne County
## 3    36121                   Wyoming County
## 4    36123                     Yates County
## 5    36AAA Suffolk County Police Department
## 6    36AAB        Westchester Public Safety
## # ... with 19 more variables: Geo_QNAME <chr>, Geo_NATION <chr>,
## #   Geo_STATE <int>, Geo_COUNTY <chr>, SE_T001_001 <int>,
## #   SE_T003_001 <dbl>, SE_T003_002 <dbl>, SE_T003_003 <dbl>,
## #   SE_T005_001 <dbl>, SE_T005_002 <dbl>, SE_T005_003 <dbl>,
## #   SE_T005_004 <dbl>, SE_T005_005 <dbl>, SE_T005_006 <dbl>,
## #   SE_T007_001 <dbl>, SE_T007_002 <dbl>, SE_T007_003 <dbl>,
## #   SE_T007_004 <dbl>, SE_T009_001 <dbl>

Recoding Variable Names

library(dplyr)
#T007_001:   Total Property Crimes Rate:
#T007_002:      Burglaries Rate
#T007_003:      Larcenies Rate
#T007_004:      Motor Vehicle Thefts Rate

Crimedata2 <- rename(CRIMEDATA, 
                         totalpropertycrime_PER_100K = SE_T007_001, 
                         BURGLARIES_PER_100K = SE_T007_002,
                         LARCENIES_PER_100K = SE_T007_003, 
                         MOTORVEHICLETHEFT_PER_100K = SE_T007_004,
                         County = Geo_NAME)

Dropping and Selecting Variables

Crimedata2 <- select(Crimedata2, totalpropertycrime_PER_100K, BURGLARIES_PER_100K, LARCENIES_PER_100K, MOTORVEHICLETHEFT_PER_100K, County)

dim(Crimedata2)
## [1] 54  5
print(Crimedata2)
## # A tibble: 54 x 5
##    totalpropertycrime_PER_100K BURGLARIES_PER_100K LARCENIES_PER_100K
##                          <dbl>               <dbl>              <dbl>
##  1                   35.554866           10.989686          23.272276
##  2                    4.213897            0.000000           4.213897
##  3                  369.848449           56.469295         305.239435
##  4                  376.017043           96.250096         263.083596
##  5                  226.088289           45.984059         173.717556
##  6                  453.436714          133.813533         299.742313
##  7                  515.671119           44.791033         458.246718
##  8                  628.531652          124.887397         479.076243
##  9                   19.692065            3.692262          15.999803
## 10                  518.623291          131.688046         377.180575
## # ... with 44 more rows, and 2 more variables:
## #   MOTORVEHICLETHEFT_PER_100K <dbl>, County <chr>

Creating New Variable

CRIMEDATA <- mutate(CRIMEDATA, 
                    TOTALPROP_VIOLENTCRIMESREP = SE_T007_001 + SE_T005_001)

head(CRIMEDATA)
## # A tibble: 6 x 22
##   Geo_FIPS           Geo_NAME                    Geo_QNAME Geo_NATION
##      <chr>              <chr>                        <chr>      <chr>
## 1    36001      Albany County      Albany County, New York       <NA>
## 2    36003    Allegany County    Allegany County, New York       <NA>
## 3    36007      Broome County      Broome County, New York       <NA>
## 4    36009 Cattaraugus County Cattaraugus County, New York       <NA>
## 5    36011      Cayuga County      Cayuga County, New York       <NA>
## 6    36013  Chautauqua County  Chautauqua County, New York       <NA>
## # ... with 18 more variables: Geo_STATE <int>, Geo_COUNTY <chr>,
## #   SE_T001_001 <int>, SE_T003_001 <dbl>, SE_T003_002 <dbl>,
## #   SE_T003_003 <dbl>, SE_T005_001 <dbl>, SE_T005_002 <dbl>,
## #   SE_T005_003 <dbl>, SE_T005_004 <dbl>, SE_T005_005 <dbl>,
## #   SE_T005_006 <dbl>, SE_T007_001 <dbl>, SE_T007_002 <dbl>,
## #   SE_T007_003 <dbl>, SE_T007_004 <dbl>, SE_T009_001 <dbl>,
## #   TOTALPROP_VIOLENTCRIMESREP <dbl>