how to speed up this double loop by vectorization in R? : I need to find the minimum distance between coordinates. Unfortunately, my data contains the coordinates in a special coordinate system and i have to calculate the distance by hand.
My double for loop (code below) is far too slow. Can someone help me vectorizing my loop?


        for (i in 1:nrow(d.small)) {
      cat(i, " ")
      for ( j in 1:nrow(haltestelle.small)) {
        diff.ost <- d.small[i, .(GKODE)] - haltestelle.small[j, .(y_Koord_Ost)]
        diff.nord <- d.small[i, .(GKODN)] - haltestelle.small[j, .(x_Koord_Nord)]
        dist.oev[i,1] <- min(sqrt(diff.ost^2 + diff.nord^2))
        dist.oev[i,2] <- which.min(sqrt(diff.ost^2 + diff.nord^2))
      }
    }

