function - R returning matrix -


I am trying to return a matrix from the function, but why it is unable to understand that it gives an error .

  rdMatrix & lt; - Function (value = 0) {x & lt; - Get diag (value) & lt; - Function () Return (x) x}  

Output:

  & gt; Rdmatrix (5) [, 1] [, 2] [, 3] [, 4] [, 5] [1,] 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 0 [4,] 0 0 0 1 0 [5,] 0 0 0 1> Receives an error in RdMatrix $ get () rdMatrix $: object type 'closure' is not tabs & gt;  

post-text "itemprop =" text ">

Perhaps you're aiming for:

  rdMatrix <- Local ({get <- function () return (x) x & lt; - NULL function (value = 0) {x  

Or maybe you prefer :

  rdMatrix & lt; - local ({x <-> NULL list (get = function) returns (x), set = function (value = 0) {x < & Lt; - diag (value)})} rdMatrix $ set (3) rdMatrix $ get ()  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -