updated R script
Added parameter for k value