Рассмотрим фрейм данных с двумя строками и уникальным номером рейса:
d <- structure(list(flight = c("N912DE", "ANCD123"), origin_lon = c(-84.42778,
-85), origin_lat = c(33.63667, 33.63667), dest_lon = c(-87.90667,
-87.90667), dest_lat = c(41.9744, 41.9744)),
row.names = c(NA, -2L), class = "data.frame")
Для каждого flight
вы можете создать последовательность в summarise
.
library(dplyr)
library(tidyr)
n <- 5
df %>%
pivot_longer(cols = c(-flight),
names_to = c('col', '.value'),
names_sep = '_') %>%
group_by(flight) %>%
summarise(lon = list(seq(max(lon), min(lon), length.out = n)),
lat = list(seq(min(lat), max(lat), length.out = n))) %>%
unnest(cols = c(lat, lon))
# A tibble: 10 x 3
# flight lon lat
# <chr> <dbl> <dbl>
# 1 ANCD123 -85 33.6
# 2 ANCD123 -85.7 35.7
# 3 ANCD123 -86.5 37.8
# 4 ANCD123 -87.2 39.9
# 5 ANCD123 -87.9 42.0
# 6 N912DE -84.4 33.6
# 7 N912DE -85.3 35.7
# 8 N912DE -86.2 37.8
# 9 N912DE -87.0 39.9
#10 N912DE -87.9 42.0