Skip to content

Commit 6e58170

Browse files
committed
Create .Rhistory
1 parent 8624dd9 commit 6e58170

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

.Rhistory

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## This function creates a special "matrix" object that can cache its inverse.
2+
makeCacheMatrix <- function(x = matrix()) {
3+
inv <- NULL # initialize inverse as NULL
4+
set <- function(y) {
5+
x <<- y # assign new matrix value
6+
inv <<- NULL # reset inverse cache
7+
}
8+
get <- function() x
9+
setinverse <- function(inverse) inv <<- inverse
10+
getinverse <- function() inv
11+
list(set = set, get = get,
12+
setinverse = setinverse,
13+
getinverse = getinverse)
14+
}
15+
## This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
16+
cacheSolve <- function(x, ...) {
17+
inv <- x$getinverse()
18+
if(!is.null(inv)) {
19+
message("getting cached data")
20+
return(inv) # return cached inverse
21+
}
22+
data <- x$get()
23+
inv <- solve(data, ...) # compute inverse
24+
x$setinverse(inv) # cache the inverse
25+
inv
26+
}

0 commit comments

Comments
 (0)