While applying a function on different datasets, I have realized for dataset with consequent amount of observation, a couple of observations are not included in the output (See y previous question st_network_blend does not include all points). So my idea is to filter the original dataset and restart the operation, bind the second output to the first one and repeat the process as long as observations are not included.
I have tried the function on below. Where I apply the function distfn()
that I have created, on the original dataframe. After, the difference between the output and the original, is extracted as Diff
. If the length of the vector Diff
is 0 then the output does not need correction. If the length is higher than 0, then the loop has to start to filter, apply the code, bind outputs and assess the difference with the original dataframe.
Distloop <- function(dfInj){
dist = distfn(dfInj)
Diff = setdiff(Inj$ID, dist$ID)
x <- as.numeric(length(Diff))
if(as.numeric(length(Diff)) == 0){
dist
} else {
while(x != 0){
dfInjb <- dfInj %>% filter(ID == Diff)
distb <- distfn(dfInjb)
dist <- dist %>% rbind(distb)
Diff = setdiff(Inj$ID, dist$ID)
x <- as.numeric(length(Diff))
}
}
}
The problem come from the while
function...
P.S.: Unfortunately, due to the size of the dataset needed to illustrate the problematic, I cannot join any reproducible example. Nevertheless, you can take a look at the example given in that question st_network_blend does not include all points