Skip to content

Instantly share code, notes, and snippets.

@ellango85
Created December 24, 2018 04:10
Show Gist options
  • Save ellango85/272a0e71c2e6e7c7f67f60a6d3c1ec3e to your computer and use it in GitHub Desktop.
Save ellango85/272a0e71c2e6e7c7f67f60a6d3c1ec3e to your computer and use it in GitHub Desktop.
Couple of functions that cache the inverse of a matrix.
##Couple of functions that cache the inverse of a matrix
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y){
x <<- y
inv <<- NULL
}
get <- function() x
setInverse <- function(solveMatrix) inv <<- solveMatrix
getInverse <- function() inv
list(set = set, get = get,
setInverse = setInverse,
getInverse = getInverse)
}
cacheSolve <- function(x, ...) {
inv <- x$getInverse()
if(!is.null(inv)){
message("getting cached data")
return(inv)
}
data <- x$get()
inv <- solve(data)
x$setInverse(inv)
inv
}
## data <- matrix(c(1, 2, 3, 0, 2, 2, 1, 3, 0), nrow=3, ncol=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment