purrr::map() in mutate() call: multiple rows per each row of data

You can unnest() the list of vectors you get in stations_c, which sounds like the kind of output you want (I may have misunderstood what the final version should look like).

The downside to this is that cities without any stations at the given distance, like LA, aren't in the output.

cities %>% 
    mutate(stations = purrr::map2(lat, long, nearest_stations, distance = 10) ) %>% 
    unnest()

           name   lat    long     stations
1      New York 40.67  -73.94 720553-99999
2      New York 40.67  -73.94 744976-99999
3      New York 40.67  -73.94 997271-99999
4       Chicago 41.84  -87.68 725340-14819
5       Chicago 41.84  -87.68 725346-94866
6       Chicago 41.84  -87.68 725346-99999
7       Chicago 41.84  -87.68 998499-99999
8       Chicago 41.84  -87.68 999999-14819
9       Chicago 41.84  -87.68 999999-94866
10      Houston 29.77  -95.39 720594-00188
...
5 Likes