R上带有循环的多处理大型列表



我有一本改编自书的代码"用R";(Kelley,2018(:

require(oce)
require(dplyr)
#transform in ctd
df <- mapply(function(dat, nm) { 
as.ctd(dat, salinity, temperature, pressure) 
},
dat = df, nm = names(df))
df <- mapply(function(dat, nm) { 
ctdTrim(dat, method = "downcast") #Smoothing dataset
},
dat = df, nm = names(df))
#Part 1 -> MLD
plotProfile(df$`2018-08-02T162038 SBE0251090`, xtype="temperature",
col.temperature="black")
temperature <- df[["temperature"]] 
pressure <- df[["pressure"]] 
for (criterion in c(1, 0.125)) { #dP of 0.125kg/m3 and dT of 1
inMLD <- abs(temperature[1]-temperature) < criterion 
MLDindex <- which.min(inMLD) 
MLDpressure <- pressure[MLDindex]
abline(h=pressure[MLDindex], lwd=2, lty="dashed")
}
MLDpressureMax =pressure[MLDindex] + MLDindex
#Thermocline
plotProfile(df$`2018-08-02T162038 SBE0251090`, xtype="N2",col.N2="black")
mid <- which.max(swN2(df$`2018-08-02T162038 SBE0251090`)) 
pstar <- pressure[mid] #give thermocline 
abline(h=pstar, lwd=2, lty="dashed")
#Compilation
##first station (Remove if not first station)
MLDAll <- data.frame(MLDmin = MLDpressure,MLDmax = MLDpressureMax, Thermocline =pstar)
MLDAll <- MLDAll |> mutate(id = rep("df"))
##following stations (Remove if first station)
#MLDAll2 <- data.frame(MLDmin = MLDpressure,MLDmax = MLDpressureMax, Thermocline =pstar)
#MLDAll2 <- MLDAll2 |> mutate(id = rep("dfn"))
#MLDAll <- rbind(MLDAll,MLDAll2)

该代码的目的是找到MLD和温跃层,并在MDLAll中提取它。它可以与给定的数据集正常工作:

df <- list(`2018-08-02T162038 SBE0251090` = structure(list(ctd_file = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), .Label = c("2018-08-02T162038 SBE0251090", "2018-08-03T090018 SBE0251090", 
"2018-08-03T183128 SBE0251090", "2018-08-05T092503 SBE0251090", 
"2018-08-05T110117 SBE0251090", "2018-08-05T113244 SBE0251090", 
"2018-08-05T190218 SBE0251090", "2018-08-06T133734 SBE0251090", 
"2018-08-06T210027 SBE0251090", "2018-08-07T072416 SBE0251090", 
"2018-08-07T154210 SBE0251090", "2018-08-08T113553 SBE0251090", 
"2018-08-08T150027 SBE0251090", "2018-08-09T080637 SBE0251090", 
"2018-08-09T083847 SBE0251090", "2018-08-09T172255 SBE0251090", 
"2018-08-09T180440 SBE0251090", "2018-08-10T144312 SBE0251090", 
"2018-08-11T063433 SBE0251090", "2018-08-11T182056 SBE0251090", 
"2018-08-12T064149 SBE0251090", "2018-08-12T143302 SBE0251090", 
"2018-08-15T082008 SBE0251090", "2018-08-17T085347 SBE0251090", 
"2018-08-17T154840 SBE0251090", "2018-08-18T123931 SBE0251090", 
"2018-08-18T195446 SBE0251090", "2018-08-19T084035 SBE0251090", 
"2018-08-19T193301 SBE0251090"), class = "factor"), latitude = c(69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667, 69.27166667, 69.27166667, 
69.27166667, 69.27166667, 69.27166667), longitude = c(-25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667, -25.15166667, -25.15166667, 
-25.15166667, -25.15166667, -25.15166667), time = c(233.213, 
233.498, 233.793, 234.066, 234.345, 234.611, 234.864, 235.09, 
235.301, 235.494, 235.688, 235.867, 236.045, 236.221, 236.383, 
236.559, 236.725, 236.902, 237.058, 237.241, 237.412, 237.594, 
237.753, 237.933, 238.106, 238.271, 238.435, 238.61, 238.775, 
238.952, 239.126, 239.327, 239.511, 239.7, 239.88, 240.09, 240.299, 
240.522, 240.736, 240.956, 241.188, 241.432, 241.666, 241.939, 
242.19, 242.444, 242.713, 242.984, 243.222, 243.486, 243.729, 
243.96, 244.204, 244.404, 244.61, 244.812, 244.998, 245.18, 245.364, 
245.546, 245.707, 245.872, 246.026, 246.202, 246.361, 246.513, 
246.676, 246.822, 246.976, 247.139, 247.292, 247.438, 247.591, 
247.767, 247.914, 248.084, 248.258, 248.455, 248.663, 248.936, 
249.192, 249.383, 249.545, 249.716, 249.906, 250.093, 250.326, 
250.584, 250.965, 251.416, 251.723, 251.933, 252.163, 252.432, 
252.786, 253.041, 253.256, 253.469, 253.655, 253.833, 254.005, 
254.157, 254.318, 254.487, 254.65, 254.836, 254.989, 255.145, 
255.289, 255.417, 255.546, 255.685, 255.831, 255.966, 256.104, 
256.254, 256.408, 256.555, 256.708, 256.864, 257.035, 257.197, 
257.374, 257.557, 257.745, 257.949, 258.18, 258.42, 258.667, 
258.948, 259.219, 259.529, 259.826, 260.137, 260.441, 260.735, 
260.997, 261.234, 261.47, 261.709, 261.913, 262.128, 262.31, 
262.49, 262.672, 262.848, 263.011, 263.167, 263.335, 263.475, 
263.634, 263.792, 263.938, 264.076, 264.225, 264.371, 264.516, 
264.655, 264.811, 264.947, 265.098, 265.239, 265.402, 265.546, 
265.696, 265.862, 266.021, 266.202, 266.381, 266.575, 266.776, 
266.997, 267.254, 267.538, 267.817, 268.136, 268.477, 268.801, 
269.135, 269.406, 269.683, 269.953, 270.179, 270.389, 270.597, 
270.774, 270.957, 271.148, 271.312, 271.464, 271.63, 271.793, 
271.938, 272.092, 272.245, 272.39, 272.534, 272.681, 272.835, 
272.984, 273.124, 273.279, 273.44, 273.596, 273.746, 273.904, 
274.064, 274.24, 274.402, 274.587, 274.772, 274.956, 275.158, 
275.366, 275.574, 275.789, 276.021, 276.271, 276.523, 276.784, 
277.057, 277.325, 277.605, 277.859, 278.109, 278.366, 278.611, 
278.838, 279.064), pressure = c(2.121, 2.223, 2.324, 2.425, 2.526, 
2.627, 2.728, 2.829, 2.93, 3.031, 3.132, 3.233, 3.334, 3.435, 
3.536, 3.637, 3.738, 3.839, 3.941, 4.041, 4.142, 4.243, 4.345, 
4.445, 4.547, 4.648, 4.749, 4.85, 4.95, 5.052, 5.153, 5.254, 
5.354, 5.456, 5.557, 5.658, 5.759, 5.86, 5.961, 6.062, 6.163, 
6.264, 6.365, 6.466, 6.567, 6.668, 6.77, 6.871, 6.972, 7.072, 
7.174, 7.274, 7.375, 7.477, 7.578, 7.678, 7.779, 7.881, 7.982, 
8.083, 8.183, 8.285, 8.386, 8.487, 8.588, 8.689, 8.79, 8.891, 
8.993, 9.094, 9.195, 9.296, 9.396, 9.497, 9.598, 9.699, 9.801, 
9.901, 10.003, 10.103, 10.205, 10.306, 10.407, 10.508, 10.609, 
10.71, 10.811, 10.912, 11.013, 11.115, 11.215, 11.316, 11.418, 
11.518, 11.619, 11.721, 11.821, 11.923, 12.023, 12.124, 12.226, 
12.327, 12.428, 12.529, 12.63, 12.73, 12.832, 12.933, 13.034, 
13.135, 13.236, 13.337, 13.438, 13.539, 13.64, 13.741, 13.843, 
13.943, 14.044, 14.145, 14.247, 14.348, 14.448, 14.549, 14.65, 
14.751, 14.853, 14.954, 15.055, 15.156, 15.257, 15.358, 15.459, 
15.56, 15.661, 15.762, 15.863, 15.964, 16.065, 16.166, 16.267, 
16.368, 16.469, 16.57, 16.672, 16.773, 16.873, 16.975, 17.075, 
17.177, 17.277, 17.379, 17.48, 17.58, 17.682, 17.783, 17.884, 
17.984, 18.086, 18.187, 18.288, 18.389, 18.49, 18.591, 18.692, 
18.793, 18.894, 18.995, 19.097, 19.198, 19.298, 19.4, 19.501, 
19.602, 19.702, 19.804, 19.905, 20.006, 20.107, 20.208, 20.309, 
20.41, 20.511, 20.612, 20.713, 20.814, 20.915, 21.017, 21.117, 
21.218, 21.319, 21.421, 21.522, 21.623, 21.724, 21.825, 21.925, 
22.027, 22.127, 22.229, 22.33, 22.431, 22.532, 22.633, 22.734, 
22.835, 22.936, 23.037, 23.138, 23.24, 23.341, 23.441, 23.542, 
23.644, 23.745, 23.846, 23.946, 24.047, 24.149, 24.25, 24.351, 
24.452, 24.553, 24.654, 24.755, 24.856, 24.957, 25.058, 25.159
), depth = c(2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 
3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 
4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 
5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 
7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8, 8.1, 8.2, 
8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9, 9.1, 9.2, 9.3, 9.4, 9.5, 
9.6, 9.7, 9.8, 9.9, 10, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 
10.8, 10.9, 11, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 
11.9, 12, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 
13, 13.1, 13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14, 
14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15, 15.1, 
15.2, 15.3, 15.4, 15.5, 15.6, 15.7, 15.8, 15.9, 16, 16.1, 16.2, 
16.3, 16.4, 16.5, 16.6, 16.7, 16.8, 16.9, 17, 17.1, 17.2, 17.3, 
17.4, 17.5, 17.6, 17.7, 17.8, 17.9, 18, 18.1, 18.2, 18.3, 18.4, 
18.5, 18.6, 18.7, 18.8, 18.9, 19, 19.1, 19.2, 19.3, 19.4, 19.5, 
19.6, 19.7, 19.8, 19.9, 20, 20.1, 20.2, 20.3, 20.4, 20.5, 20.6, 
20.7, 20.8, 20.9, 21, 21.1, 21.2, 21.3, 21.4, 21.5, 21.6, 21.7, 
21.8, 21.9, 22, 22.1, 22.2, 22.3, 22.4, 22.5, 22.6, 22.7, 22.8, 
22.9, 23, 23.1, 23.2, 23.3, 23.4, 23.5, 23.6, 23.7, 23.8, 23.9, 
24, 24.1, 24.2, 24.3, 24.4, 24.5, 24.6, 24.7, 24.8, 24.9), salinity = c(30.2477, 
30.2556, 30.2839, 30.2777, 30.2869, 30.2802, 30.2759, 30.2743, 
30.2642, 30.2757, 30.2791, 30.291, 30.3045, 30.39, 30.4223, 30.3371, 
30.4686, 30.5722, 30.6134, 30.6391, 30.6429, 30.6473, 30.6566, 
30.6723, 30.6845, 30.6947, 30.6926, 30.6933, 30.7016, 30.6995, 
30.7043, 30.711, 30.7174, 30.7193, 30.7307, 30.7407, 30.7491, 
30.7697, 30.7075, 30.8744, 30.9353, 30.9555, 30.9619, 30.9671, 
30.9703, 30.9707, 30.982, 30.9852, 30.9948, 30.995, 30.9949, 
30.9992, 31.0017, 31.005, 31.0052, 31.0136, 31.0135, 31.0249, 
31.0284, 31.0359, 31.0396, 31.0363, 31.0374, 31.0406, 31.0386, 
31.0403, 31.043, 31.0413, 31.0427, 31.0475, 31.0438, 31.041, 
31.0421, 31.0423, 31.0425, 31.0433, 31.0411, 31.0342, 31.0419, 
31.0461, 31.0466, 31.0469, 31.0486, 31.0468, 31.0388, 31.0424, 
31.0419, 31.0514, 31.0546, 31.0574, 31.0581, 31.0643, 31.0639, 
31.0636, 31.0647, 31.0701, 31.0748, 31.0712, 31.0776, 31.0776, 
31.0724, 31.0706, 31.0734, 31.077, 31.0747, 31.0853, 31.091, 
31.1004, 31.113, 31.1218, 31.1291, 31.1296, 31.1314, 31.1293, 
31.1316, 31.1344, 31.1332, 31.1366, 31.1369, 31.1384, 31.1396, 
31.1401, 31.1407, 31.1409, 31.1419, 31.143, 31.1433, 31.1433, 
31.1435, 31.1441, 31.1445, 31.1453, 31.1452, 31.145, 31.1477, 
31.15, 31.147, 31.1489, 31.149, 31.1482, 31.1479, 31.1529, 31.1463, 
31.1496, 31.1489, 31.1494, 31.1521, 31.1507, 31.1491, 31.1544, 
31.1622, 31.158, 31.1588, 31.1589, 31.1515, 31.1511, 31.1532, 
31.1497, 31.1574, 31.1523, 31.1471, 31.1504, 31.1632, 31.1503, 
31.1528, 31.1576, 31.1616, 31.1553, 31.1534, 31.1566, 31.1592, 
31.1572, 31.151, 31.1539, 31.154, 31.1548, 31.1569, 31.1544, 
31.1557, 31.154, 31.1595, 31.1546, 31.1561, 31.1548, 31.1641, 
31.1583, 31.1517, 31.1509, 31.158, 31.157, 31.152, 31.1611, 31.1635, 
31.1566, 31.1568, 31.158, 31.1892, 31.1903, 31.1907, 31.1908, 
31.1912, 31.2053, 31.2312, 31.2399, 31.2422, 31.2427, 31.2431, 
31.2428, 31.2419, 31.2419, 31.2402, 31.2399, 31.2412, 31.2423, 
31.2386, 31.2425, 31.2501, 31.2313, 31.2541, 31.2573, 31.2581, 
31.2593, 31.2614, 31.2615, 31.2632, 31.2638, 31.2665, 31.2661, 
31.2662), temperature = c(2.6608, 2.6794, 2.6949, 2.6895, 2.6911, 
2.6849, 2.6788, 2.6679, 2.6707, 2.6868, 2.69, 2.6927, 2.7276, 
2.8024, 2.799, 2.8014, 2.9505, 3.033, 3.048, 3.0486, 3.0485, 
3.0484, 3.0456, 3.0366, 3.0254, 3.0215, 3.0201, 3.0237, 3.0274, 
3.0262, 3.0396, 3.049, 3.0521, 3.0602, 3.0748, 3.0954, 3.1051, 
3.1131, 3.1534, 3.2785, 3.3218, 3.3321, 3.3362, 3.3403, 3.3415, 
3.3469, 3.3611, 3.368, 3.3781, 3.3756, 3.3783, 3.3836, 3.3883, 
3.3908, 3.3961, 3.3971, 3.4097, 3.4249, 3.438, 3.4515, 3.4541, 
3.4482, 3.4523, 3.4542, 3.4548, 3.459, 3.4611, 3.462, 3.4656, 
3.4627, 3.453, 3.4533, 3.4538, 3.4538, 3.454, 3.4541, 3.4541, 
3.4665, 3.4813, 3.4784, 3.4741, 3.4726, 3.4672, 3.4585, 3.4636, 
3.4826, 3.4968, 3.5073, 3.508, 3.5059, 3.5088, 3.5094, 3.506, 
3.5083, 3.5119, 3.5183, 3.5183, 3.5201, 3.5231, 3.5178, 3.5132, 
3.5154, 3.5203, 3.5237, 3.5271, 3.5415, 3.5531, 3.5627, 3.573, 
3.5717, 3.561, 3.5578, 3.5557, 3.5534, 3.5544, 3.5517, 3.5557, 
3.5615, 3.5642, 3.5668, 3.5681, 3.568, 3.568, 3.5687, 3.5689, 
3.5679, 3.5667, 3.5661, 3.5677, 3.5681, 3.568, 3.565, 3.5619, 
3.5611, 3.5629, 3.5512, 3.5466, 3.5465, 3.5401, 3.5353, 3.5335, 
3.5297, 3.5293, 3.5337, 3.5342, 3.5354, 3.5322, 3.5251, 3.5261, 
3.5227, 3.5015, 3.4722, 3.4552, 3.4397, 3.4292, 3.4322, 3.4319, 
3.428, 3.4313, 3.4157, 3.4189, 3.4259, 3.4105, 3.3982, 3.3921, 
3.3862, 3.3723, 3.3589, 3.3628, 3.3616, 3.3513, 3.3394, 3.3456, 
3.3512, 3.3485, 3.3489, 3.344, 3.3394, 3.3327, 3.3413, 3.3251, 
3.3141, 3.3116, 3.3078, 3.2953, 3.2736, 3.2659, 3.2797, 3.2768, 
3.2614, 3.2614, 3.2536, 3.2437, 3.2293, 3.2464, 3.251, 3.2259, 
3.1659, 3.1472, 3.1448, 3.1571, 3.1691, 3.1665, 3.1558, 3.1514, 
3.1467, 3.144, 3.1426, 3.1411, 3.1406, 3.1397, 3.1429, 3.1461, 
3.1471, 3.1484, 3.1624, 3.1628, 3.1689, 3.2096, 3.2145, 3.2173, 
3.2227, 3.2259, 3.2254, 3.228, 3.2277, 3.2258, 3.2206, 3.2194
), conductivity = c(2.747973, 2.750277, 2.753504, 2.752757, 2.753371, 
2.752425, 2.751543, 2.750481, 2.750393, 2.752359, 2.752809, 2.754133, 
2.759305, 2.771334, 2.77227, 2.769065, 2.79073, 2.804569, 2.808717, 
2.810867, 2.811178, 2.81154, 2.811976, 2.812462, 2.812764, 2.813319, 
2.813123, 2.813579, 2.814405, 2.814347, 2.815775, 2.817025, 2.817804, 
2.818807, 2.82086, 2.823313, 2.824983, 2.826606, 2.827446, 2.849715, 
2.857663, 2.859997, 2.860879, 2.861614, 2.861985, 2.862599, 2.864543, 
2.865483, 2.866943, 2.866779, 2.867092, 2.86783, 2.868436, 2.868897, 
2.869404, 2.870149, 2.871424, 2.873497, 2.874913, 2.87641, 2.876747, 
2.876198, 2.876638, 2.876958, 2.876954, 2.877427, 2.877739, 2.877765, 
2.878133, 2.878054, 2.877133, 2.877013, 2.877123, 2.877132, 2.877183, 
2.877216, 2.87714, 2.87785, 2.879394, 2.879395, 2.879123, 2.878948, 
2.878574, 2.877938, 2.878032, 2.879666, 2.880849, 2.882188, 2.882583, 
2.882648, 2.883038, 2.883466, 2.883214, 2.883439, 2.883812, 2.884819, 
2.885096, 2.885135, 2.885723, 2.885237, 2.884582, 2.884686, 2.885309, 
2.885825, 2.886179, 2.888128, 2.889594, 2.891213, 2.892878, 2.893187, 
2.893114, 2.892966, 2.892905, 2.892687, 2.892879, 2.89297, 2.893351, 
2.893984, 2.89424, 2.894554, 2.894732, 2.894759, 2.894831, 2.894909, 
2.894994, 2.894999, 2.894942, 2.894912, 2.895074, 2.895146, 2.89516, 
2.894961, 2.894724, 2.894703, 2.894983, 2.894205, 2.893697, 2.893759, 
2.893266, 2.892848, 2.892717, 2.892687, 2.892403, 2.892905, 2.892908, 
2.892989, 2.89284, 2.892283, 2.892238, 2.892187, 2.890743, 2.888315, 
2.886969, 2.885807, 2.88473, 2.884909, 2.884931, 2.884594, 2.884852, 
2.883667, 2.883704, 2.884272, 2.883672, 2.882021, 2.881792, 2.881516, 
2.880633, 2.879405, 2.879592, 2.879619, 2.878891, 2.877887, 2.878145, 
2.878653, 2.878439, 2.878502, 2.878276, 2.877796, 2.877365, 2.877845, 
2.876838, 2.875755, 2.875608, 2.875249, 2.874591, 2.8726, 2.871829, 
2.872851, 2.872818, 2.871691, 2.871314, 2.871152, 2.870549, 2.869671, 
2.870666, 2.870849, 2.869996, 2.86629, 2.865346, 2.865394, 2.866574, 
2.868532, 2.870122, 2.870135, 2.869979, 2.869693, 2.869547, 2.869401, 
2.869243, 2.869193, 2.869022, 2.869292, 2.869655, 2.869729, 2.869787, 
2.87114, 2.871482, 2.871342, 2.875943, 2.87653, 2.876835, 2.877372, 
2.877766, 2.87776, 2.878106, 2.878119, 2.878111, 2.877727, 2.877665
)), row.names = c(NA, 229L), class = "data.frame"))

该代码一次只适用于一个样本(在这种情况下为工作站(。尽管如此,我将不得不在随后的大量电台上应用此代码。考虑到一个由不同站点组成的名为AllStations的大列表,我如何在不同的站点之间循环它?(由于字符数量有限,将通过复制df创建大列表AllStations(

df1 <- df
df2 <- df
df3 <- df
df4 <- df
AllStations <- list(df, df1, df2, df3, df4)

我已经可以用mapply迭代部分代码,但不能迭代全部。。。就像这里的plotProfile()

mapply(function(dat, nm) { 
plotProfile(dat, xtype="temperature",
col.temperature="black") 
},
dat = AllStations, nm = names(AllStations))

您可以考虑使用并行计算以高效的方式完成所有这些处理。下面是的一个例子

fn_Par <- function(df)
{
require(oce)
require(dplyr)
df <- mapply(function(dat, nm) { 
as.ctd(dat, salinity, temperature, pressure) 
},
dat = df, nm = names(df))
df <- mapply(function(dat, nm) { 
ctdTrim(dat, method = "downcast") #Smoothing dataset
},
dat = df, nm = names(df))

plotProfile(df$`2018-08-02T162038 SBE0251090`, xtype="temperature",
col.temperature="black")
temperature <- df[["temperature"]] 
pressure <- df[["pressure"]] 

for(criterion in c(1, 0.125)) 
{
#dP of 0.125kg/m3 and dT of 1
inMLD <- abs(temperature[1] - temperature) < criterion 
MLDindex <- which.min(inMLD) 
MLDpressure <- pressure[MLDindex]
abline(h=pressure[MLDindex], lwd = 2, lty = "dashed")
}

MLDpressureMax <- pressure[MLDindex] + MLDindex

#Thermocline

plotProfile(df$`2018-08-02T162038 SBE0251090`, xtype = "N2", col.N2 = "black")
mid <- which.max(swN2(df$`2018-08-02T162038 SBE0251090`)) 
pstar <- pressure[mid] #give thermocline 
abline(h = pstar, lwd = 2, lty = "dashed")

MLDAll <- data.frame(MLDmin = MLDpressure,MLDmax = MLDpressureMax, Thermocline = pstar)
MLDAll <- MLDAll |> mutate(id = rep("df"))
return(MLDAll)
}
df1 <- df
df2 <- df
df3 <- df
df4 <- df
AllStations <- list(df, df1, df2, df3, df4)
library(parallel)
library(doParallel)
nb_CPU <- 5
cluster <- parallel::makeCluster(nb_CPU)
doParallel::registerDoParallel(cl = cluster)
list_Res <- parLapply(cluster, X = AllStations, fun = fn_Par)

最新更新