1

So I have a dataframe with coordinates and site id's for 117 sites and I want to filter it and make a new df which only contains the data of a select 50 sites, of which the ID's are in another df. Below is my code, however I got this error "longer object length is not a multiple of shorter object length"

Code:

longlat_LH <- longlat %>% filter(site_id == LH_sites$site_id)
Martin Gal
  • 16,640
  • 5
  • 21
  • 39

1 Answers1

1

Match can be useful in your case

longlat_LH <- longlat[match(LH_sites$site_id, longlat$site_id), ]

And with dplyr just like @Imran suggested try

longlat %>%
   filter(site_id %in% LH_sites$site_id)`
linkonabe
  • 661
  • 7
  • 23
  • @neil Langan, If we have answered your question correctly, its always a good practice to *[vote up](https://stackoverflow.com/help/privileges/vote-up) – linkonabe Jul 28 '20 at 13:27