Logo Lanfrica

chan571/Shark-Attack-Fatality-Analysis

Creator:
cha
Host:
Perform data cleaning and exploratory analysis to assess the comparative risk of shark attacks on people between Australia and South Africa. ## Introduction As part of this practice, we are tackling fundamental programming tasks in R, focusing on data cleaning and exploratory analysis. We are working on Global Shark Attack file, a compilation of all reported shark attacks on humans. The question we aim to address is: Which country, Australia or South Africa, poses a greater risk in terms of shark attacks on people? Let's get started! ## Load standard library ``` library("tidyverse") library("dplyr") library("ggplot2") ``` ## Data Exploration and Cleaning There are 24 variables and 25827 cases in this data ``` data The key variables we need to address the question are *Year*,*Country*,*Fatal..Y.N.*. All of these variables have some missing values. The column name 'Fatal..Y.N.' is not very intuitive, so let's change it to simply 'Fatal'. ``` rename_data % select(Year, Fatal..Y.N., Country) %>% filter(Year>0) %>% rename(Fatal = Fatal..Y.N.) ``` We are going to focus on recent time span. The range of *Year* is 0 - 2021. ``` range_year % select(Date, Year) %>% filter(Year == 0) head(year_zero,6) count(year_zero) ``` There are 129 cases with Year value equal to ‘0’. Some of the data dates back a long time ago, mostly from late 1800 and onwards. However, there are also a number of years before Christ (B.C.), due to various sources contributing to this data, some of which are hard to validate for accuracy. For instance, the case with date ‘Ca. 725 B.C.’, the data could come from a work of fiction, given that it originates from a book published in 1958. ``` data %>% filter(Date == "Ca. 725 B.C.") ``` The analysis will concentrate on data from 2012 to 2021, as there's an increasing trend in shark-related incidents reported after 2000. This range provides recent and focused data, with fewer missing values for the variable 'fatal incidents', resulting in 1204 cases. ``` #Check how many cases have been recorded and organize them by year in descending order. total_cases % select(Year, Fatal) %>% filter(Ye …