###################<-60 Characters Wide->################### # sort.rows() # W. A. Green # Department of Geology, Yale University # walton.green@yale.edu # # Last Modified: May 6, 2005 # Sort the rows of a matrix based on all columns, starting at the # leftmost column and continuing to the right as far as necessary # to entirely resolve the sort. # x is a matrix or data frame and the arguments decreasing and # na.last can be passed to order() via ... (default is # na.last = TRUE, decreasing = FALSE). sort.rows <- function(x, ...){ xcols <- vector(length = ncol(x), mode = 'list') for(i in 1:ncol(x)){ xcols[[i]] <- as.vector(x[,i]) } names(xcols) <- paste (rep('x', ncol(x)), 1:ncol(x), sep = '') x <- x[do.call('order', c(xcols, ...)),] return(x) } # End of function