如果探测器只在下倾期间下降,即不存在这种情况
深度(i) > 深度(i+1)
对于属于同一向下转换的单元格,则此代码有效。
它认为当一个单元格的深度小于其前一个单元格的深度时 - 请参阅diff(x) 的文档 - 向下转换已经结束。所以你可能想在使用它之前对你的约会进行消毒。我已经设置了一个温度列表来演示如何扩展其他参数的使用。
## create test data for depth "Z" and temperature "T"
dc1.Z <- seq(10,100,1)
dc1.T <- seq(15, 3, length.out=length(dc1.Z))
dc2.Z <- seq(10,90,1)
dc2.T <- seq(18, 1, length.out=length(dc2.Z))
dc3.Z <- seq(20,80,1)
dc3.T <- seq(10, 2, length.out=length(dc3.Z))
dc4.Z <- seq(10,95,1)
dc4.T <- seq(15, 5, length.out=length(dc4.Z))
## join data as specified
dc.Z <- c(dc1.Z, dc2.Z, dc3.Z, dc4.Z)
dc.T <- c(dc1.T, dc2.T, dc3.T, dc4.T)
## get indexes for points where depth increases
## the 'plus one' is to target the first values of a downcast
## instead of the last ones, so splitAt will work properly
indexes <- which(diff(dc.Z) < 0) + 1
## define function for spliting a list at given indexes and use it
splitAt <- function(x, pos) unname(split(x, cumsum(seq_along(x) %in% pos)))
splited.dc.Z <- splitAt(dc.Z, indexes)
splited.dc.T <- splitAt(dc.T, indexes)
## check if each of the splited values match the original
all(dc1.Z == splited.dc.Z[[1]])
all(dc1.T == splited.dc.T[[1]])
all(dc2.Z == splited.dc.Z[[2]])
all(dc2.T == splited.dc.T[[2]])
all(dc3.Z == splited.dc.Z[[3]])
all(dc3.T == splited.dc.T[[3]])
all(dc4.Z == splited.dc.Z[[4]])
all(dc4.T == splited.dc.T[[4]])
我从this question得到了函数splitAt