For this module I decided to look back at module 2: data manipulation and create a Markdown document. ## Reading data into R For the first part of this assignment, we must first load the Bird Flu data into R:
Bird_deaths = read.csv("BirdFlu_deaths.csv")
names(Bird_deaths)
## [1] "Country" "yr2003" "yr2004" "yr2005" "yr2006" "yr2007" "yr2008"
length(Bird_deaths)
## [1] 7
str(Bird_deaths)
## 'data.frame': 15 obs. of 7 variables:
## $ Country: chr "Azerbaijan" "Bangladesh" "Cambodia" "China" ...
## $ yr2003 : int 0 0 0 1 0 0 0 0 0 0 ...
## $ yr2004 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ yr2005 : int 0 0 4 5 0 0 13 0 0 0 ...
## $ yr2006 : int 5 0 2 8 0 10 45 2 0 0 ...
## $ yr2007 : int 0 0 1 3 0 9 37 0 2 0 ...
## $ yr2008 : int 0 0 0 3 0 3 15 0 0 0 ...
As you can see, we also utilized the names(), head() and str() functions to get a general overview of the datasets structure.
From there we will find the maximum number of deaths for 2005.
Bird_2005 = max(Bird_deaths$yr2005)
Bird_2005
## [1] 19
We can use the next bit of code to locate the location of the number within the dataframe.
which(Bird_deaths$yr2005 == 19)
## [1] 15
Bird_deaths[15,1]
## [1] "Vietnam"
By finding the location and plugging it into the row section of the matrix, we are able to find out what country has the most bird deaths in 2005. We can utilize the same method in order to find maximum number of deaaths in 2007 as shown below:
Bird_2007 = max(Bird_deaths$yr2007)
Bird_2007
## [1] 37
which(Bird_deaths$yr2007 == 37)
## [1] 7
Bird_deaths[7,1]
## [1] "Indonesia"