Using R To Optimize N