I hacked into a small recursive function that finds all consecutive triplets among the many vectors that you pass (you need to go through at least three). This is probably a little rude, but it seems to work.
The function uses an ellipsis ... to pass arguments. Therefore, you will need many arguments (for example, number vectors) that you provide, and put them in the items list. Then the smallest value among each past vector is located, as well as its index.
Then the indices of the vectors corresponding to the smallest triplet are executed and repeated using the for() loop, where the output values ββare passed to the output vector out . The input vectors in items clipped and returned to the function in a recursive manner. Only when all vectors are NA , i.e. There are more values ββin vectors, the function returns the final result.
library(magrittr)
A function can be called by passing input vectors as arguments.
The result is a list containing all the necessary information, albeit disordered.
print(y) # [[1]] # [1] 1 2 3 # # [[2]] # [1] 4 5 6 # # [[3]] # [1] 7 9 NA # # [[4]] # [1] 8 NA NA
You can order everything with sapply() :
# put everything in order sapply(y, function(x){x[order(x)]}) %>% t
The fact is that it will use only one value for each vector to find triplets. Therefore, he will not find a consecutive triplet c(6,7,8) among, for example, c(6,7,11) , c(8,9,13) and c(10,12,14) . In this case, it will return c(6,8,10) (see below).
a<-c(6,7,11) b<-c(8,9,13) c<-c(10,12,14) y <- tripl(a,b,c) sapply(y, function(x){x[order(x)]}) %>% t