-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm_iso_generate_df.R
180 lines (115 loc) · 5.24 KB
/
mm_iso_generate_df.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
library(ggplot2)
# set working directory
wd <- setwd("C:/Users/IOtte/documents/Desktop/training/")
# read.data
dat.iso <- read.csv2("iso_calc.csv", header = T)
# delete observations without precipitation
dat.iso.cmpl <- dat.iso[complete.cases(dat.iso), ]
# subset per plot
iso.fer0 <- subset(dat.iso.cmpl, plot_id_sp1 == "fer0")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.fer0.rn <- subset(iso.fer0, type == "rain")
iso.fer0.tf <- subset(iso.fer0, type == "tf")
iso.fer0.fg <- subset(iso.fer0, type == "fog")
# merge data
ls.iso.fer0 <- list(iso.fer0.rn, iso.fer0.tf, iso.fer0.fg)
df.iso.fer0.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.fer0)
# remove incomplete records
df.iso.fer0.mrg.nw <- df.iso.fer0.mrg[complete.cases(df.iso.fer0.mrg), ]
# in-between values
mm.fer0 <- subset(df.iso.fer0.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
#####################################
# subset per plot
iso.foc0 <- subset(dat.iso.cmpl, plot_id_sp1 == "foc0")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.foc0.rn <- subset(iso.foc0, type == "rain")
iso.foc0.tf <- subset(iso.foc0, type == "tf")
iso.foc0.fg <- subset(iso.foc0, type == "fog")
# merge data
ls.iso.foc0 <- list(iso.foc0.rn, iso.foc0.tf, iso.foc0.fg)
df.iso.foc0.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.foc0)
# remove incomplete records
df.iso.foc0.mrg.nw <- df.iso.foc0.mrg[complete.cases(df.iso.foc0.mrg), ]
# in-between values
mm.foc0 <- subset(df.iso.foc0.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
###################################
# subset per plot
iso.flm1 <- subset(dat.iso.cmpl, plot_id_sp1 == "flm1")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.flm1.rn <- subset(iso.flm1, type == "rain")
iso.flm1.tf <- subset(iso.flm1, type == "tf")
iso.flm1.fg <- subset(iso.flm1, type == "fog")
# merge data
ls.iso.flm1 <- list(iso.flm1.rn, iso.flm1.tf, iso.flm1.fg)
df.iso.flm1.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.flm1)
# remove incomplete records
df.iso.flm1.mrg.nw <- df.iso.flm1.mrg[complete.cases(df.iso.flm1.mrg), ]
# in-between values
mm.flm1 <- subset(df.iso.flm1.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
#######################################
# subset per plot
iso.foc6 <- subset(dat.iso.cmpl, plot_id_sp1 == "foc6")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.foc6.rn <- subset(iso.foc6, type == "rain")
iso.foc6.tf <- subset(iso.foc6, type == "tf")
iso.foc6.fg <- subset(iso.foc6, type == "fog")
# merge data
ls.iso.foc6 <- list(iso.foc6.rn, iso.foc6.tf, iso.foc6.fg)
df.iso.foc6.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.foc6)
# remove incomplete records
df.iso.foc6.mrg.nw <- df.iso.foc6.mrg[complete.cases(df.iso.foc6.mrg), ]
# in-between values
mm.foc6 <- subset(df.iso.foc6.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
#######################################
# subset per plot
iso.fpo0 <- subset(dat.iso.cmpl, plot_id_sp1 == "fpo0")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.fpo0.rn <- subset(iso.fpo0, type == "rain")
iso.fpo0.tf <- subset(iso.fpo0, type == "tf")
iso.fpo0.fg <- subset(iso.fpo0, type == "fog")
# merge data
ls.iso.fpo0 <- list(iso.fpo0.rn, iso.fpo0.tf, iso.fpo0.fg)
df.iso.fpo0.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.fpo0)
# remove incomplete records
df.iso.fpo0.mrg.nw <- df.iso.fpo0.mrg[complete.cases(df.iso.fpo0.mrg), ]
# in-between values
mm.fpo0 <- subset(df.iso.fpo0.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
#######################################
# subset per plot
iso.fpd0 <- subset(dat.iso.cmpl, plot_id_sp1 == "fpd0")[, c(1, 2, 4, 5, 7, 8)]
# subset data by rain, tf and fog
iso.fpd0.rn <- subset(iso.fpd0, type == "rain")
iso.fpd0.tf <- subset(iso.fpd0, type == "tf")
iso.fpd0.fg <- subset(iso.fpd0, type == "fog")
# merge data
ls.iso.fpd0 <- list(iso.fpd0.rn, iso.fpd0.tf, iso.fpd0.fg)
df.iso.fpd0.mrg <- Reduce(function(...) merge(..., by = c(1, 2, 3), all = TRUE),
ls.iso.fpd0)
# remove incomplete records
df.iso.fpd0.mrg.nw <- df.iso.fpd0.mrg[complete.cases(df.iso.fpd0.mrg), ]
# in-between values
mm.fpd0 <- subset(df.iso.fpd0.mrg.nw,
(d18_16.y < d18_16) & (d18_16.y > d18_16.x) |
(d18_16.y > d18_16) & (d18_16.y < d18_16.x))
### join all subsets to one data.frame
oco <- merge(mm.foc0, mm.foc6, all = TRUE)
podo <- merge(mm.fpd0, mm.fpo0, all = TRUE)
rst <- merge(mm.flm1, mm.fer0, all = TRUE)
oco.podo <- merge(oco, podo, all = TRUE)
mm.iso <- merge(oco.podo, rst, all = TRUE)
write.csv2(mm.iso, file = "mm.iso.csv")