We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e03c611 commit 797dc86Copy full SHA for 797dc86
cachematrix.R
@@ -5,12 +5,32 @@
5
## matrix inversion calculations.
6
7
makeCacheMatrix <- function(x = matrix()) {
8
-
+inv <- NULL
9
+set <- function(y) {
10
+ x <<- y
11
+ inv <<- NULL
12
+}
13
+get <- function() x
14
+setinverse <- function(solve) inv <<- solve
15
+getinverse <- function() solve
16
+list(set = set,
17
+ get = get,
18
+ setinverse = setinverse,
19
+ getinverse = getinverse)
20
}
21
22
23
## This function calculates the inverse.
24
25
cacheSolve <- function(x, ...) {
- ## Return a matrix that is the inverse of 'x'
26
+ ## Return a matrix that is the inverse of 'x'
27
+inv <- x$getinverse()
28
+if(!is.null(inv)) {
29
+ message("getting cached data")
30
+ return(inv)
31
32
+data <- x$get()
33
+inv <- mean(data, ...)
34
+x$setinverse(inv)
35
+inv
36
0 commit comments