Convert Matlab To R