Updated R file. sort=FALSE in merge does not work. Had to use inner_join in dplyr.