## Load CURL
## Load CURL
install.packages("bitops", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/hz/_6wwrssj6rqfv564qhlxzhdw0000gn/T//RtmpVaodjV/downloaded_packages
library(bitops)
library(RCurl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
tryCatch(
{
arrests_github_file <- getURL("https://vincentarelbundock.github.io/Rdatasets/csv/carData/Arrests.csv")
arrests_df <- read.csv(text = x)
# Show Total Summerize Data
summary(arrests_df)
arrests_df %>% summarize(AvgAgeTotal=mean(age))
## Show the average age of males vs females in the group
arrests_df %>% group_by(sex) %>% summarize(AverageAgeBySex=mean(age))
arrests_df %>% group_by(sex) %>% summarize(MediumAgeBySex=median(age))
## Show the average age of white vs black
arrests_df %>% group_by(colour) %>% summarize(AvgAge=mean(age))
arrests_df %>% group_by(colour) %>% summarize(MediumAge=median(age))
## Lets extract offenders who are under 18 years old and store into a dataframe
under20_arrests_df <- arrests_df %>% filter(age <= 18)
# Show Total Summerize Data for arrests under 18 years old
summary(under20_arrests_df)
## Show the average age of males vs females in the sub group
under20_arrests_df %>% group_by(sex) %>% summarize(AverageAgeBySex=mean(age))
under20_arrests_df %>% group_by(sex) %>% summarize(MediumAgeBySex=median(age))
## Show the average age of white vs black in the sub group
under20_arrests_df %>% group_by(colour) %>% summarize(AvgAge=mean(age))
under20_arrests_df %>% group_by(colour) %>% summarize(MediumAge=median(age))
## Rename e with excellent in the sex column
under20_arrests_df[,"sex"] <- gsub("e", "excellent", under20_arrests_df[,"sex"])
}, error = function(err)
{
print(paste("File doesn't exist: ", err))
}
)
## [1] "File doesn't exist: Error in textConnection(text, encoding = \"UTF-8\"): object 'x' not found\n"