FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ProgrammingAssignment2/CompleteRfileCode at master · JA2014/ProgrammingAssignment2 · GitHub
JA2014
/
ProgrammingAssignment2
Public
forked from
rdpeng/ProgrammingAssignment2
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ProgrammingAssignment2
/
CompleteRfileCode
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (38 loc) · 2.1 KB
Breadcrumbs
ProgrammingAssignment2
/
CompleteRfileCode
Copy path
File metadata and controls
48 lines (38 loc) · 2.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
this is the code from my complete R file.
## In this assignments, there are 2 functions. The first one creates a special “matrix” object that can cache its inverse;
## the second one computes the inverse of the special "matrix" returned by makeCacheMatrix. If the inverse has already been calculated
## (and the matrix has not changed), then the cachesolve should retrieve the inverse from the cache.
## Write a short comment describing the first function 'makeCacheMatrix'
## MakeCacheMatrix:this function creates a special “matrix” object that can cache its inverse.
makeCacheMatrix <- function(x = matrix()) {
cacheMatrix <- NULL # assign NULL to an object cacheMatrix
set <- function(y) { # assign a value to an objects in an environment
# that is different from the current environment
x <<- y
cacheMatrix <<- NULL
}
get <- function() x # this function get the value of the matrix
setsolve <- function(solve) cacheMatrix <<- solve #this function set
#the value of the inverse matrix in the cache
getsolve <- function() cacheMatrix # this function get the value of the
# inverse matrix from the cache
list(set = set, get = get,
setsolve = setsolve,
getsolve = getsolve)
}
## Write a short comment describing the second function 'cacheSolve'
## cacheSolve: this function computes the inverse of the special "matrix" returned by makeCacheMatrix.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
cacheMatrix <- x$getsolve()
if(!is.null(cacheMatrix)) { # checks to see if the inverse matrix has
# already been calculated.If so, it gets the
# value from the cache and return it.
message("getting cached data")
return(cacheMatrix)
}
data <- x$get() # this portion calculates the inverse of the matrix and sets the value in the cache via the setmean function
cacheMatrix <- solve(data, ...)
x$setSolve(cacheMatrix)
cacheMatrix
}
Back
|
FazBrowse Home
|
New Git URL