[R] Issue writing correct code for Coursera assignment--performing matrix inversion
Samuel Colon
scolon725 at gmail.com
Thu Feb 19 21:13:32 CET 2015
Hello All,
I'm new to this mailing list, so please let me know if I've committed any
posting faux-pas.
I'm working on an assignment for my Coursera course; please see my code
below in which I have tried to write two functions--to perform the task of
matrix inversion and then caching that data. My code is below:
makeCacheMatrix <- function(x = matrix()) {
i <- NULL
set <- function(y) {
x <<- y
i <<- NULL
}
get <- function() x
setinverse <- function(solve) i <<- solve
getinverse <- function() i
list(set = set, get = get, setinverse = setinverse,
getinverse = getinverse)
}
cacheSolve <- function(x, ...) {
i <- x$getinverse()
if(!is.null(i)) {
message("getting cached data")
return(i)
}
data <- i$get()
i <- solve(data, ...)
x$setinverse(i)
i
}
After I create a new matrix, x, and try to run cacheSolve(x), I receive
this error: "attempt to apply non-function."
I'm new to using the <<- operator, so I'm not sure if that's where my error
is?
Can anyone suggest how I can go about debugging the above code?
Thanks very much,
Sam Colon
Coursera Student
[[alternative HTML version deleted]]
More information about the R-help
mailing list