0

I'm trying to plot air mass back trajectories. I currently have code, which works perfectly for a single point, looping through running the model every three hours. Here's the key part of that code:

lapply(files, function(x) file.remove(x))
start <- paste(year, "-01-01", sep = "")
end <- paste(year, "-12-31 18:00", sep = "")
dates <- seq(as.POSIXct(start, "GMT"), as.POSIXct(end, "GMT"), by = "3 hour")
for (i in 1:length(dates)) {
year <- format(dates[i], "%y")
Year <- format(dates[i], "%Y") # long format
month <- format(dates[i], "%m")
day <- format(dates[i], "%d")
hour <- format(dates[i], "%H")

However, I've been trying to add an extra layer to this. Currently, it loops through and runs the calculation every three hours. Now, for each of those three hour intervals, I need it to use a new longitude and latitude for the calculation. Any advice as to how I could go about adding this detail?

I was thinking of using something along the lines of:

purrr::map_2(long, lat, ~some_function_of(.x, .y)) 

…but despite hours looking at cheat sheets trying to teach myself how to use this function I'm getting nowhere.

Any suggestions?

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
dh1069
  • 1
  • Without posting your data or at least an example dataset that resembles your data structure it is hard to help you. Look [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to learn how to make a reproducible example. – Till Jul 16 '21 at 19:11

0 Answers0