File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,7 @@ cachemean <- function(x, ...) {
43
43
44
44
# makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.
45
45
makeCacheMatrix <- function (x = matrix ()){
46
- specialMatrix <- matrix ()
47
-
46
+ specialMatrix <- data.frame (" matrix" = x , " inverse" = matrix ())
48
47
49
48
specialMatrix
50
49
}
@@ -54,13 +53,12 @@ makeCacheMatrix <- function(x = matrix()){
54
53
# If the inverse has already been calculated (and the matrix has not changed),
55
54
# then the cachesolve should retrieve the inverse from the cache.
56
55
cacheSolve <- function (x , ... ){
57
- cache <- matrix ()
58
56
# Computing the inverse of a square matrix can be done with the solve function in R.
59
57
# For example, if X is a square invertible matrix, then solve(X) returns its inverse.
60
- if (! cache $ matrixIn ){
61
- cache $ matrixIn <- solve(matrixIn )
58
+ if (! x $ inverse ){
59
+ x $ inverse <- solve(x )
62
60
}
63
61
64
62
# # Return a matrix that is the inverse of 'x'
65
- cache $ matrixIn
63
+ x $ inverse
66
64
}
You can’t perform that action at this time.
0 commit comments