MichielvEldik / MSc_MADS_2021

0 stars 1 forks source link

Fix distancjes #1

Closed MichielvEldik closed 3 years ago

MichielvEldik commented 3 years ago

I thought that the two distances were long and latitude distances. They aren't. The first represents the first euclidean distance, the second represents the euclidean distance to the second nearest neighbor. For some reason I specified there to be two neighbors and this isn't really necessary...

https://cran.r-project.org/web/packages/FNN/FNN.pdf

nn2 <- get.knnx( external_data[,c("udh.lat", "udh.long")], internal_data[,c("centroid_lat", "centroid_long")], 2)

internal_data$local_index <- c(1:nrow(internal_data)) external_data$local_index <- c(1:nrow(external_data))

internal_data$index_other_data <- nn2$nn.index[,1] internal_data$dist_lat <- nn2$nn.dist[,1] internal_data$dist_long <- nn2$nn.dist[,2] internal_data$total_distancjes <- internal_data$dist_lat + internal_data$dist_long