Module 6 Report

Author

Richard Stratton

Module 2 Exercise 1 Report

Code

First, I read in the data with the following function:

bflu = read.csv("BirdFlu_deaths.csv")

Then, the following function showed the names of all of the columns:

names(bflu)
[1] "Country" "yr2003"  "yr2004"  "yr2005"  "yr2006"  "yr2007"  "yr2008" 

The head() function was then used to see what the first few rows and columns looked like:

head(bflu)
     Country yr2003 yr2004 yr2005 yr2006 yr2007 yr2008
1 Azerbaijan      0      0      0      5      0      0
2 Bangladesh      0      0      0      0      0      0
3   Cambodia      0      0      4      2      1      0
4      China      1      0      5      8      3      3
5   Djibouti      0      0      0      0      0      0
6      Egypt      0      0      0     10      9      3

str() was used to find out what data type the file is:

str(bflu)
'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 ...

Then a new variable was created by calculating the max value for the year 2005

max_row = which(bflu$yr2005 == max(bflu$yr2005))

Using the new variable, the max value was printed, which shows the country with the most cases for 2005.

bflu[max_row,]
   Country yr2003 yr2004 yr2005 yr2006 yr2007 yr2008
15 Vietnam      3     20     19      0      5      5

A second new variable was created by calculating the max value for the year 2007.

max_row2 = which(bflu$yr2007 == max(bflu$yr2007))

This new variable was also used to show the country with the most cases in 2007.

bflu[max_row2,]
    Country yr2003 yr2004 yr2005 yr2006 yr2007 yr2008
7 Indonesia      0      0     13     45     37     15

Fin