Reduce use of subset in gapfilling
after:
fill.tmp<-subset(mdata,id.ok %in% c("generic","few","invalid","missing") & dflag <= 1 )
add
fill.tmp<-fill.tmp[,c("date","lat","lon","new.id","uid","date","group","dck")]
replace
tofill<-subset(sp.fill[[igroup]],!(sp.fill[[igroup]]$date %in% sub$date))[,c("date","lat","lon","new.id","uid","date","group","dck")]
with
tofill<-subset(sp.fill[[igroup]],!(sp.fill[[igroup]]$date %in% sub$date) & sp.fill[[igroup]]$date > min(sub$date) - 3*24*60*60 & sp.fill[[igroup]]$date < min(sub$date) + 3*24*60*60)
(Edited by @dyb for easier reading)