use of R bind in new_merge_ids_year
Iterative use of rbind (i.e. in a loop) leads to poor performance, recommend preallocating data frames and then filling.
Preallocate data frame
Line 399:
tr.add <- c()
replace with
max_rows = nrow( mdata )
tr.add <- data.frame( uid <- rep(NA_character_, max_rows), trk = rep(NA_integer_, max_rows), few = rep(NA_integer_, max_rows),
speed = rep(NA_real_, max_rows), course = rep(NA_real_, max_rows) )
row_position <- 0
Fill
Line 461:
tr.add<-rbind(tr.add,data.frame(tr))
replace with
tr.add[ row_position + 1:length(tr$uid) , ] <- data.frame( tr )
row_position <- row_position + length(tr$uid)
and then at end of loop between lines 464 and 465 insert
tr.add <- tr.add[ 1:row_position, ]
I've only tested very briefly so the above needs checking fully.