I have a question about reading certain files in a folder. For example, there are files in the folder "wind_grids", with file names as wind_lat1_lon1, wind_lat1_lon2, wind_lat1_lon3, ..., wind_lat2_lon1, wind_lat2_lon2, wind_lat2_lon3, .... Now I have another excel file with two columns: longitude, latitude. I want to exclude these coordinates in the excel file that appear in the wind_grids folder, because these grids are not necessary to show up. How to realize this? Thanks for your help.
I think this can be done by applying string manipulations to the list of files, but we would need some sample data to provide a practical example, could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
If you've never heard of a reprex before, you might want to start by reading this FAQ:
EDIT: The solution I have in mind would be similar to this
For example, in 'wind_grids' directory, there are files named wind_39.9375_-105.3125, wind_39.9375_ -105.4375, wind_40.0625_-105.3125, wind_40.0625_-105.4375, etc.
In the excel file, either df.xls or df.csv file, there are two columns:
lon lat
-105.3125 39.9375
-105.3125 40.0625
...
How to exclude the wind_lat_lon in the excel file from the 'wind_grids' folder? Thanks for your help.
Where could the problem be? Thanks.
I checked that str_detect(string, pattern) has no statement such as "negate = TRUE", so may be I have a different version than yours?
Thanks, the sample data works. However, there are a lager number of files in the "wd.files" folder, and some have names like "wind_40.1250_-105.5000", "wind_41.0500_-106.5000", etc. And in the "excel_df" data frame, the coordinates are 40.125, -105.5, etc., so is there a way to keep four decimal spaces when reading the excel_df? This way, the str_detect function can recognize all corresponding string names. Thanks again.