I cannot resolve the error: βthe wrong length for the vector must be 2β when trying to calculate the distance (distance between the runways) between two points (thresholds / ends of the runway). To make things worse, I donβt understand the answers, for example here Error R: the wrong length for the vector should be 2 and apply them to my case. A simplified data frame (runway end position) is as follows:
runways <- data.frame( RWY_ID = c(1,2,3) ,RWY = c("36R", "36L","01") ,LAT = c(40.08, 40.12, 40.06) ,LON = c(116.59, 116.57, 116.62) ,LAT2 = c(40.05, 40.07,40.09) ,LON2 = c(116.6, 116.57, 116.61) )
Using the distHaversine () function from the geosphere, I am trying to calculate the distance:
runways <- mutate(runways , CTD = distHaversine( c(LON, LAT), c(LON2, LAT2)) )
I'm not sure what I'm doing wrong here. If I pulled out the LON LAT position, it is a numerical vector with the correct length.
myv <- c(runways$LON[1], runways$LAT[1]) myv [1] 116.59 40.08 str(myv) num [1:2] 116.6 40.1
source share