Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb8f2e0

Browse files
committed
first pass at solution
1 parent efaf537 commit bb8f2e0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cachematrix.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
## makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.
1010

1111
makeCacheMatrix <- function(x = matrix()) {
12+
m <- NULL
13+
set <- function(y) {
14+
x <<- y
15+
m <<- NULL
16+
}
17+
get <- function() x
18+
setmatrix <- function(matrix) m <<- mean
19+
getmatrix <- function() m
1220

1321
}
1422

@@ -19,5 +27,13 @@ makeCacheMatrix <- function(x = matrix()) {
1927
## retrieve the inverse from the cache.
2028

2129
cacheSolve <- function(x, ...) {
22-
## Return a matrix that is the inverse of 'x'
30+
m <- x$getmatrix()
31+
if(!is.null(m)) {
32+
message("getting cached data")
33+
return(m)
34+
}
35+
data <- x$get()
36+
m <- matrix(data, ...)
37+
x$setmatrix(m)
38+
m
2339
}

0 commit comments

Comments
 (0)