Module 06
In this module I will take the module 04 assignment and move it into a quarto document and host it on RPubs.com .
Module 04
Question 1
Estimate the mean and standard deviation for temperature and salinity across all samples.
cat ("Mean temperature:" , mean (temp$ Temperature, na.rm = TRUE ), " \n " )
Mean temperature: 12.20743
cat ("Mean salinity:" , mean (temp$ Salinity, na.rm = TRUE ), " \n " )
cat ("Standard deviation of temperature:" , sd (temp$ Temperature, na.rm = TRUE ), " \n " )
Standard deviation of temperature: 5.412521
cat ("Standard deviation of salinity:" , sd (temp$ Salinity, na.rm = TRUE ), " \n " )
Standard deviation of salinity: 5.421593
Question 2
Using tapply() estimate the average values of temperature and salinity across a) all sites and b) all years
cat ("--- Mean Temperature by Station --- \n " )
--- Mean Temperature by Station ---
print (tapply (temp$ Temperature, temp$ Station, mean, na.rm = TRUE ))
DANT DREI G6 GROO HAMM HANS HUIB LODS
12.05908 12.77160 10.66570 12.25853 12.50000 13.54894 11.85353 12.61192
MARS N02 N10 N20 N70 R03 R50 R70
12.39607 11.37433 12.45878 12.19753 12.14789 12.80000 13.94911 13.98022
SOEL T004 T010 T100 T135 T175 T235 VLIS
13.21203 11.28425 12.37517 11.94766 11.75512 11.55431 11.32355 12.79292
W02 W20 W70 WISS ZIJP ZUID
10.51829 11.87937 12.18243 12.45090 12.55904 11.83928
cat ("--- Mean Salinity by Station --- \n " )
--- Mean Salinity by Station ---
print (tapply (temp$ Salinity, temp$ Station, mean, na.rm = TRUE ))
DANT DREI G6 GROO HAMM HANS HUIB LODS
28.94468 29.83813 30.59610 14.57571 31.35738 18.29124 29.52631 30.73000
MARS N02 N10 N20 N70 R03 R50 R70
28.03457 28.78695 30.45223 31.93275 34.94147 30.54978 33.49888 33.67944
SOEL T004 T010 T100 T135 T175 T235 VLIS
18.09477 32.08114 32.72095 34.56746 34.67667 34.75135 34.87812 29.55476
W02 W20 W70 WISS ZIJP ZUID
32.05992 33.31554 35.02006 31.75164 29.39230 28.83997
cat ("--- Mean Temperature by Year --- \n " )
--- Mean Temperature by Year ---
print (tapply (temp$ Temperature, temp$ Year, mean, na.rm = TRUE ))
1990 1991 1992 1993 1994 1995 1996 1997
11.99146 11.00885 11.55799 11.45385 12.07944 12.32080 10.72728 12.33687
1998 1999 2000 2001 2002 2003 2004 2005
12.13386 13.10577 12.61539 12.74162 13.05500 12.69017 12.56788 12.56112
cat ("--- Mean Salinity by Year --- \n " )
--- Mean Salinity by Year ---
print (tapply (temp$ Salinity, temp$ Year, mean, na.rm = TRUE ))
1990 1991 1992 1993 1994 1995 1996 1997
30.89873 30.88625 30.27116 29.52839 29.07707 28.94954 30.66670 30.54525
1998 1999 2000 2001 2002 2003 2004 2005
29.55748 29.03291 28.99534 28.22390 28.89323 29.60946 30.45629 30.35355
Question 3
Using aggregate(), estimate the average monthly values of temperature and salinity by year across all sites to make a time series
monthly_ts_data <- aggregate (cbind (Temperature, Salinity) ~ Year + Month, data = temp, FUN = mean, na.rm = TRUE )
summary (monthly_ts_data)
Year Month Temperature Salinity
Min. :1990 Min. : 1.00 Min. : 1.751 Min. :25.16
1st Qu.:1994 1st Qu.: 3.75 1st Qu.: 6.618 1st Qu.:28.68
Median :1998 Median : 6.50 Median :11.319 Median :29.93
Mean :1998 Mean : 6.50 Mean :11.438 Mean :29.60
3rd Qu.:2001 3rd Qu.: 9.25 3rd Qu.:16.020 3rd Qu.:30.65
Max. :2005 Max. :12.00 Max. :21.038 Max. :31.99
Question 4
Use the table() function to determine the number of observations: at each station, for each year, at each station per year
DANT DREI G6 GROO HAMM HANS HUIB LODS MARS N02 N10 N20 N70 R03 R50 R70
300 293 278 296 295 309 296 294 296 402 665 266 268 161 106 106
SOEL T004 T010 T100 T135 T175 T235 VLIS W02 W20 W70 WISS ZIJP ZUID
295 339 261 258 259 258 258 421 272 191 190 296 296 303
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
367 392 438 436 590 590 583 636 608 570 563 568 545 550 540 552
table (temp$ Station, temp$ Year)
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
DANT 12 12 18 19 17 13 19 20 22 21 22 21 21 21
DREI 13 13 13 13 19 21 20 20 21 20 20 20 20 20
G6 12 16 20 17 21 24 23 28 23 21 13 12 12 12
GROO 12 12 18 19 17 12 18 19 21 21 21 21 21 21
HAMM 13 13 13 13 20 21 20 21 20 20 21 20 20 20
HANS 13 16 13 13 21 24 19 19 18 18 29 29 20 19
HUIB 12 11 18 19 17 12 19 19 21 21 21 22 21 21
LODS 13 13 13 13 20 21 20 21 20 20 20 20 20 20
MARS 12 12 18 18 16 12 19 19 22 21 21 21 21 21
N02 12 17 20 17 27 29 31 40 37 29 24 27 23 23
N10 47 45 40 46 53 56 43 52 45 43 36 37 30 31
N20 12 12 11 11 18 18 18 18 18 18 19 19 19 19
N70 12 11 11 11 18 18 18 18 18 19 18 20 20 19
R03 0 5 7 7 13 17 17 23 20 9 8 7 7 7
R50 0 5 7 7 10 7 7 7 7 7 7 7 7 7
R70 0 5 7 7 10 7 7 7 7 7 7 7 7 7
SOEL 13 13 13 12 20 22 20 21 20 20 20 20 20 20
T004 12 14 20 16 26 27 27 33 28 20 19 19 19 20
T010 12 10 11 10 18 18 18 18 18 18 18 18 18 19
T100 12 10 10 10 18 18 18 18 18 18 18 18 18 18
T135 12 10 10 10 18 18 18 18 18 18 17 19 18 19
T175 12 10 10 10 18 18 18 18 18 18 18 18 18 18
T235 12 10 10 10 18 18 18 18 18 18 18 18 18 18
VLIS 14 18 21 24 35 36 22 23 22 22 30 31 30 32
W02 12 17 20 17 21 23 23 28 23 16 12 12 12 12
W20 12 12 11 11 12 12 12 12 12 13 12 12 12 12
W70 12 12 11 11 12 12 12 12 12 12 12 12 12 12
WISS 13 13 13 13 20 21 20 22 20 20 21 20 20 20
ZIJP 13 13 13 13 20 21 20 23 20 20 20 20 20 20
ZUID 11 12 18 19 17 14 19 21 21 22 21 21 21 22
2004 2005
DANT 21 21
DREI 20 20
G6 12 12
GROO 21 22
HAMM 20 20
HANS 19 19
HUIB 21 21
LODS 20 20
MARS 21 22
N02 22 24
N10 29 32
N20 17 19
N70 18 19
R03 7 7
R50 7 7
R70 7 7
SOEL 20 21
T004 19 20
T010 18 19
T100 18 18
T135 18 18
T175 18 18
T235 18 18
VLIS 31 30
W02 12 12
W20 12 12
W70 12 12
WISS 20 20
ZIJP 20 20
ZUID 22 22