Install data.table and read in the Temperature file.
Select only the columns Area, Season and Temperature
temp[ , .(Area, Season, Temperature)]
Area Season Temperature
<char> <char> <num>
1: WZ winter 4.00
2: WZ winter 6.00
3: WZ spring 7.30
4: WZ spring 8.20
5: WZ spring 17.40
---
8524: WZ autumn 15.47
8525: WZ autumn 13.45
8526: WZ autumn 12.09
8527: WZ autumn 9.03
8528: WZ winter 5.13
Select only the columns Area and Temperature but only for winter observations
winter[ , .(Area, Temperature)]
Area Temperature
<char> <num>
1: WZ 4.00
2: WZ 6.00
3: WZ 4.20
4: WZ -0.30
5: WZ 3.90
---
1702: WZ 4.40
1703: WZ 4.72
1704: WZ 3.57
1705: WZ 1.31
1706: WZ 5.13
Find the total number of observations in winter
Calculate the mean temperature and mean salinity in winter
winter[ , .(MeanTemp = mean (Temperature, na.rm = TRUE ),
MeanSal = mean (Salinity, na.rm = TRUE ))]
MeanTemp MeanSal
<num> <num>
1: 5.57162 29.15756
Find the number of observations per station in winter
winter[ , .N, by = Station]
Station N
<char> <int>
1: DANT 50
2: DREI 52
3: G6 101
4: GROO 50
5: HAMM 55
6: HANS 56
7: HUIB 50
8: LODS 54
9: MARS 49
10: N02 115
11: N10 131
12: N20 50
13: N70 50
14: R03 32
15: SOEL 50
16: T004 97
17: T010 45
18: T100 45
19: T135 46
20: T175 45
21: T235 45
22: VLIS 84
23: W02 99
24: W20 47
25: W70 47
26: WISS 55
27: ZIJP 54
28: ZUID 52
Station N
<char> <int>
Find the number of observations per station per season
temp[ , .N, by = .(Station, Season)]
Station Season N
<char> <char> <int>
1: DANT winter 50
2: DANT spring 89
3: DANT summer 89
4: DANT autumn 72
5: DREI winter 52
---
114: ZIJP autumn 61
115: ZUID winter 52
116: ZUID spring 89
117: ZUID summer 89
118: ZUID autumn 73
Estimate average temperatures by month
monthTemp = temp[ , .(MeanTemp = mean (Temperature, na.rm = TRUE )),
keyby = Month]
monthTemp
Key: <Month>
Month MeanTemp
<int> <num>
1: 1 5.174210
2: 2 4.737400
3: 3 6.125961
4: 4 8.702035
5: 5 12.293479
6: 6 15.659933
7: 7 18.077343
8: 8 19.388355
9: 9 16.995974
10: 10 13.619670
11: 11 9.848891
12: 12 6.746339
Estimate average temperatures by month by area
monthAreaTemp = temp[ , .(MeanTemp = mean (Temperature, na.rm = TRUE )),
keyby = .(Area, Month)]
monthAreaTemp
Key: <Area, Month>
Area Month MeanTemp
<char> <int> <num>
1: ED 1 3.086333
2: ED 2 3.306667
3: ED 3 5.648000
4: ED 4 9.470000
5: ED 5 14.025161
---
116: WZ 8 19.548851
117: WZ 9 15.905122
118: WZ 10 12.288816
119: WZ 11 8.261600
120: WZ 12 4.985111
Plot the output of the previous question using ggplot2 using the geom_line() geometry
ggplot (monthAreaTemp, aes (x = Month, y = MeanTemp, color = Area)) +
geom_line () +
xlab ("Month" ) +
ylab ("Mean Temperature (C)" ) +
ggtitle ("Average Temperature by Month and Area" )