Created
June 2, 2016 02:22
-
-
Save nharrell04/3b3582cdf359657daf121da0da0fcc59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
makeVector <- function(x = numeric()) { | |
m <- NULL | |
set <- function(y) { | |
x <<- y | |
m <<- NULL | |
} | |
get <- function() x | |
setmean <- function(mean) m <<- mean | |
getmean <- function() m | |
list(set = set, get = get, | |
setmean = setmean, | |
getmean = getmean) | |
} | |
cachemean <- function(x, ...) { | |
m <- x$getmean() | |
if(!is.null(m)) { | |
message("getting cached data") | |
return(m) | |
} | |
data <- x$get() | |
m <- mean(data, ...) | |
x$setmean(m) | |
m | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment