1

In the following function, I need to add a custom error message, when the dimension of the vector mu and the dimensions of the matrix sigma do not match.

This is the template for the function I want to use:

myfunction = function(mu,sigma) { return(mu %*% sigma)  }

Anyone knows how to do that?

user20650
  • 24,654
  • 5
  • 56
  • 91
Lescano64
  • 11
  • 3
  • 2
    you can add `if` conditions and `stop` i.e. `if(length(mu) != nrow(sigma)) stop("oh no")` – user20650 Apr 25 '20 at 23:17
  • 1
    "myfunction" = function(mu,sigma){ if (!dim(mu)[2] == dim(sigma)[1]){ print("Error: dimensions do not match") } else { return(mu %*% sigma) } } – Tim K Apr 25 '20 at 23:23

0 Answers0