File tree Expand file tree Collapse file tree 1 file changed +18
-19
lines changed Expand file tree Collapse file tree 1 file changed +18
-19
lines changed Original file line number Diff line number Diff line change 33
44# # This function creates a special "matrix" object that can cache its inverse.
55
6- makeVector <- function (my_x = matrix ()) {
7- my_inv <- NULL
8- set <- function (x ) {
9- my_x <<- x ;
10- my_inv <<- NULL ;
6+ makeVector <- function (m = numeric ()) {
7+ my <- NULL
8+ set <- function (y ) {
9+ x <<- y ;
10+ m <<- NULL ;
1111 }
12- get <- function () my_x ;
13- setinv <- function (inv ) my_inv <<- inv ;
14- getinv <- function () my_inv ;
15- list (set = set ,
16- get = get ,
17- setinv = setinv ,
18- getinv = getinv )
12+ get <- function () x ;
13+ setmean <- function (mean ) my <<- mean ;
14+ getmean <- function () m ;
15+ list (set = set , get = get ,
16+ setmean = setmean ,
17+ getmean = getmean )
1918}
2019
2120# # This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
2221# # If the inverse has already been calculated (and the matrix has not changed), then the
2322# # cachesolve should retrieve the inverse from the cache.
2423
2524cachemean <- function (x , ... ) {
26- my_inv <- x $ getinv()
27- if (! is.null(my_inv )) {
28- message(" Looking up data from cache " )
29- my_inv
25+ m <- x $ getinv()
26+ if (! is.null(m )) {
27+ message(" getting cached data" )
28+ return ( m )
3029 }
3130 data <- x $ get()
32- my_inv <- solve (data , ... )
33- x $ setinv( my_inv )
34- my_inv
31+ x <- mean (data , ... )
32+ x $ setmean( m )
33+ m
3534}
You can’t perform that action at this time.
0 commit comments