Module 6 Deliverable

Author

Vivian Strange

Module 2 Exercise - Part One

1a : Read the data into R

setwd("~/Desktop/geog5680/Module Deliverables/Module 6")
read.csv("BirdFlu_deaths.csv")
                            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
7                         Indonesia      0      0     13     45     37     15
8                              Iraq      0      0      0      2      0      0
9  Lao.People.s.Democratic.Republic      0      0      0      0      2      0
10                          Myanmar      0      0      0      0      0      0
11                          Nigeria      0      0      0      0      1      0
12                         Pakistan      0      0      0      0      1      0
13                         Thailand      0     12      2      3      0      0
14                           Turkey      0      0      0      4      0      0
15                          Vietnam      3     20     19      0      5      5
birdflu = read.csv("BirdFlu_deaths.csv")

1b : Use the functions names(), head() and str() in R to view the data and get an overview of its structure.

names(birdflu)
[1] "Country" "yr2003"  "yr2004"  "yr2005"  "yr2006"  "yr2007"  "yr2008" 
head(birdflu)
     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(birdflu)
'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 ...

1c : Find the row number containing highest number of deaths for 2005 using the which() function.

which(birdflu$yr2005 == max(birdflu$yr2005, na.rm = TRUE))
[1] 15

1d : Use this (the row number) to identify the country with the highest number of deaths in 2005, using R’s indexing notation ([row, col]).

birdflu[15, "Country"]
[1] "Vietnam"

1e : Use the same method to find the highest number of deaths in 2007.

which(birdflu$yr2007 == max(birdflu$yr2007, na.rm = TRUE))
[1] 7
birdflu[7, "Country"]
[1] "Indonesia"

Module 2 Exercise - Part Two

2a : Read this file containing measurements of atmospheric CO2 concentration (co2_mm_mlo.txt) again.

co2 <- read.table("co2_mm_mlo.txt", col.names = c("year", "month", "decdate", "average", "interpolated", "trend", "ndays"))

2b : Create a vector containing all CO2 concentrations for all years up to and including 1985 (Use the column headed ‘interpolated’ for the CO2 values).

co2$interpolated[co2$year <= 1985]
  [1] 315.71 317.45 317.50 317.10 315.86 314.93 313.20 312.66 313.33 314.67
 [11] 315.62 316.38 316.71 317.72 318.29 318.15 316.54 314.80 313.84 313.26
 [21] 314.80 315.58 316.43 316.97 317.58 319.02 320.03 319.59 318.18 315.91
 [31] 314.16 313.83 315.00 316.19 316.93 317.70 318.54 319.48 320.58 319.77
 [41] 318.57 316.79 314.80 315.38 316.10 317.01 317.94 318.56 319.68 320.63
 [51] 321.01 320.55 319.58 317.40 316.26 315.42 316.69 317.69 318.74 319.08
 [61] 319.86 321.39 322.25 321.47 319.74 317.77 316.21 315.99 317.12 318.31
 [71] 319.57 320.07 320.73 321.77 322.25 321.89 320.44 318.70 316.70 316.79
 [81] 317.79 318.71 319.44 320.44 320.89 322.13 322.16 321.87 321.39 318.81
 [91] 317.81 317.30 318.87 319.42 320.62 321.59 322.39 323.87 324.01 323.75
[101] 322.39 320.37 318.64 318.10 319.79 321.08 322.07 322.50 323.04 324.42
[111] 325.00 324.09 322.55 320.92 319.31 319.31 320.72 321.96 322.57 323.15
[121] 323.89 325.02 325.57 325.36 324.14 322.03 320.41 320.25 321.31 322.84
[131] 324.00 324.42 325.64 326.66 327.34 326.76 325.88 323.67 322.38 321.78
[141] 322.85 324.11 325.03 325.99 326.87 328.13 328.07 327.66 326.35 324.69
[151] 323.10 323.16 323.98 325.13 326.17 326.68 327.18 327.78 328.92 328.57
[161] 327.34 325.46 323.36 323.57 324.80 326.01 326.77 327.63 327.75 329.72
[171] 330.07 329.09 328.05 326.32 324.93 325.06 326.50 327.55 328.54 329.56
[181] 330.30 331.50 332.48 332.07 330.87 329.31 327.51 327.18 328.16 328.64
[191] 329.35 330.71 331.48 332.65 333.19 332.16 331.07 329.12 327.32 327.28
[201] 328.30 329.58 330.73 331.46 331.90 333.17 333.94 333.45 331.98 329.95
[211] 328.50 328.34 329.37 330.58 331.58 332.75 333.52 334.64 334.77 334.00
[221] 333.06 330.68 328.95 328.75 330.15 331.62 332.66 333.13 334.95 336.13
[231] 336.93 336.17 334.88 332.56 331.29 331.27 332.41 333.60 334.95 335.25
[241] 336.66 337.69 338.03 338.01 336.41 334.41 332.37 332.41 333.75 334.90
[251] 336.14 336.69 338.27 338.95 339.21 339.26 337.54 335.75 333.98 334.19
[261] 335.31 336.81 337.90 338.34 340.01 340.93 341.48 341.33 339.40 337.70
[271] 336.19 336.15 337.27 338.32 339.29 340.55 341.62 342.53 343.03 342.54
[281] 340.78 338.44 336.95 337.08 338.58 339.88 340.96 341.73 342.81 343.97
[291] 344.63 343.79 342.32 340.09 338.28 338.29 339.60 340.90 341.68 342.90
[301] 343.33 345.25 346.03 345.63 344.19 342.27 340.35 340.38 341.59 343.05
[311] 344.10 344.79 345.52 346.84 347.63 346.98 345.53 343.55 341.40 341.67
[321] 343.10 344.70 345.21 346.16 347.74 348.34 349.06 348.38 346.71 345.02
[331] 343.27 343.13 344.49 345.88
pre.incl.1985 = co2$interpolated[co2$year <= 1985]

2c : Create a vector containing all CO2 concentrations for all years following 1985.

co2$interpolated[co2$year > 1985]
  [1] 346.56 347.28 348.01 349.77 350.38 349.93 348.16 346.08 345.22 344.51
 [11] 345.93 347.22 348.52 348.73 349.73 351.31 352.09 351.53 350.11 348.08
 [21] 346.52 346.59 347.96 349.16 350.39 351.64 352.40 353.69 354.21 353.72
 [31] 352.69 350.40 348.92 349.13 350.20 351.41 352.91 353.27 353.96 355.64
 [41] 355.86 355.37 353.99 351.81 350.05 350.25 351.49 352.85 353.80 355.04
 [51] 355.73 356.32 357.32 356.34 354.84 353.01 351.31 351.62 353.07 354.33
 [61] 354.84 355.73 357.23 358.66 359.13 358.13 356.19 353.85 352.25 352.35
 [71] 353.81 355.12 356.25 357.11 357.86 359.09 359.59 359.33 357.01 354.94
 [81] 352.96 353.32 354.32 355.57 357.00 357.31 358.47 359.27 360.19 359.52
 [91] 357.33 355.64 354.03 354.12 355.41 356.91 358.24 358.92 359.99 361.23
[101] 361.65 360.81 359.38 357.46 355.73 356.08 357.53 358.98 359.92 360.86
[111] 361.83 363.30 363.69 363.19 361.64 359.12 358.17 357.99 359.45 360.68
[121] 362.07 363.24 364.17 364.57 365.13 364.92 363.55 361.38 359.54 359.58
[131] 360.89 362.24 363.09 364.03 364.51 366.35 366.64 365.59 364.31 362.25
[141] 360.29 360.82 362.49 364.38 365.27 365.98 367.24 368.66 369.42 368.99
[151] 367.82 365.95 364.02 364.40 365.52 367.13 368.18 369.07 369.68 370.99
[161] 370.96 370.30 369.45 366.90 364.81 365.37 366.72 368.10 369.29 369.55
[171] 370.60 371.82 371.58 371.70 369.86 368.13 367.00 367.03 368.37 369.67
[181] 370.59 371.51 372.43 373.37 373.85 373.22 371.51 369.61 368.18 368.45
[191] 369.76 371.24 372.53 373.20 374.12 375.02 375.76 375.52 374.01 371.85
[201] 370.75 370.55 372.25 373.79 374.88 375.64 376.45 377.73 378.60 378.28
[211] 376.70 374.38 373.17 373.15 374.66 375.99 377.00 377.87 378.88 380.35
[221] 380.62 379.69 377.47 376.01 374.25 374.46 376.16 377.51 378.46 379.73
[231] 380.77 382.29 382.45 382.21 380.74 378.74 376.70 377.00 378.35 380.11
[241] 381.38 382.20 382.67 384.61 385.03 384.05 382.46 380.41 378.85 379.13
[251] 380.15 381.82 382.89 383.90 384.58 386.50 386.56 386.10 384.50 381.99
[261] 380.96 381.12 382.45 383.94 385.52 385.82 386.03 387.21 388.54 387.76
[271] 386.36 384.09 383.18 382.99 384.19 385.56 386.94 387.48 388.82 389.55
[281] 390.14 389.48 388.03 386.11 384.74 384.43 386.02 387.42 388.70 390.20
[291] 391.17 392.46 393.00 392.15 390.20 388.35 386.85 387.24 388.67 389.79
[301] 391.33 391.86 392.60 393.25 394.19 393.74 392.51 390.13 389.08 389.00
[311] 390.28 391.86 393.12 393.86 394.40 396.18 396.74 395.71 394.36 392.39
[321] 391.11 391.05 392.98 394.34 395.55 396.80 397.43 398.41 399.78 398.61
[331] 397.32 395.20 393.45 393.70 395.16 396.84 397.85 398.01 399.77 401.38
[341] 401.78 401.25 399.10 397.03 395.38 396.03 397.28 398.91 399.98 400.28
[351] 401.54 403.28 403.96 402.80 401.31 398.93 397.63 398.29 400.16 401.85
[361] 402.56 404.12 404.87 407.45 407.72 406.83 404.41 402.27 401.05 401.59
[371] 403.55 404.45 406.17 406.46 407.22 409.04 409.69 408.88 407.12 405.13
[381] 403.37 403.63 405.12 406.81 407.96 408.32 409.41 410.24 411.24 410.79
[391] 408.71 406.99 405.51 406.00 408.02 409.07 410.83 411.75 411.97 413.32
[401] 414.66 413.92 411.77 409.94 408.54 408.53 410.27 411.76 413.40 414.11
[411] 414.50
post.1985 = co2$interpolated[co2$year > 1985]

2d : Estimate the mean CO2 concentration for each of these vectors.

mean(pre.incl.1985)
[1] 328.5344
mean(post.1985)
[1] 376.5662

2e : Convert the months in the CO2 data frame to factors and create a new column called ‘fmnth’ to store this in the data frame.

co2$fmnth <- factor(co2$month)

2f : Use the levels() and table() functions to a) make sure this worked, and b) see how many observations you have for each month.

levels(co2$fmnth)
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12"
table(co2$fmnth)

 1  2  3  4  5  6  7  8  9 10 11 12 
62 62 63 62 62 62 62 62 62 62 62 62