Skip to content

Instantly share code, notes, and snippets.

@maptracker
Last active November 6, 2015 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptracker/07390983253758614ecc to your computer and use it in GitHub Desktop.
Save maptracker/07390983253758614ecc to your computer and use it in GitHub Desktop.
#R code for a #random #matrix
randomMatrix <- function( rows = 1000, cols = NULL, min = 1, max = 100) {
# Originally from my Coursera assignment: https://github.com/maptracker/ProgrammingAssignment2/blob/master/cachematrix.R
# Returns a rows x cols matrix of random numbers
# If columns are not defined, then set them to number of rows:
if (is.null(cols)) cols <- rows
# Generate random integers to put into the matrix
random <- runif( cols * rows, min = min, max = max + 1)
# Create and return the matrix:
matrix( as.integer(random), nrow = rows, ncol = cols)
}
# can use with source("https://gist.github.com/maptracker/07390983253758614ecc/raw/5995a7c1112420b64ff33dcb1e7dac679d05dbf9/randomMatrix.R")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment