Last active
November 6, 2015 18:22
-
-
Save maptracker/07390983253758614ecc to your computer and use it in GitHub Desktop.
#R code for a #random #matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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