wrote sort and return indices and vector until R utility functions are accessible