I am unable to resolve the error: "wrong length for vector, should be 2" when trying to calculate the (runway length) distance between two points (runway thresholds / ends). To make things worse, I fail to understand answers like here R error: Wrong length for a vector, should be 2 and apply them to my case. A simplified data frame of (runway end) positions looks like this:
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 geosphere, I try to calculate the distance:
runways <- mutate(runways
, CTD = distHaversine( c(LON, LAT), c(LON2, LAT2))
)
I am not sure what I do wrong here. If I pull out the LON LAT position, it is a numerical vector with the right length.
myv <- c(runways$LON[1], runways$LAT[1])
myv
[1] 116.59 40.08
str(myv)
num [1:2] 116.6 40.1