I have a data frame with latitude and longitude of a particular place. one place can have multiple lat, longs and those lat, long values can be same or different. I need to find the correct lat, long based on no.of occurances of lat, long for particular place.
example input data frame
df:
place lat long
hsy 7.343 32.849
hsy 7.343 32.122
hsy 7.567 31.567
hsy 6.934 32.122
bls 2.67 6.2
bls 3.345 5.9
bls 2.987 6.321
bls 2.987 4.56
bls 1.876 6.321
bls 2.987 6.321
expected output data frame
place lat long
hsy 7.343 32.122
bls 2.987 6.321
expected output for lat is which ever value is occurred more times among its values for particular place and the output for 'long' column value also which ever value is occurred more times among its values for particular place.
tried below code using across, but across is not working. getting Error: 'across' is not an exported object from 'namespace:dplyr' or could not find function "across" error. any alternative for across function?
df %>%
group_by(place) %>%
summarise(across(c(lat, long),~names(sort(table(.x), decreasing = TRUE))[1]))