scramble <- function(x) x[sample(nrow(x)), sample(ncol(x))]
# By default, ordering of rows and columns ignored
all.equal(mtcars, scramble(mtcars))
# But those can be overriden if desired
all.equal(mtcars, scramble(mtcars), ignore_col_order = FALSE)
all.equal(mtcars, scramble(mtcars), ignore_row_order = FALSE)
Run the code above in your browser using DataCamp Workspace