Evaluate an Expression in R Programming – eval() Function
eval() function in R Language is used to evaluate an expression passed to it as argument.
Syntax: eval(expr)
Parameters:
expr: expression to be evaluated
Example 1:
# R program to evaluate an expression # Calling eval() Functioneval(sin(pi / 3))eval(5 + 2)eval(cos(2)) |
Output:
[1] 0.8660254 [1] 7 [1] -0.4161468
Example 2:
# R program to evaluate an expression # Creating a vectorx <- c(1, 2, 3) # Creating a matrixmat <- matrix(c(2, 7, 5, 7), 2) # Calling eval() functioneval(x * 2)eval(det(mat)) |
Output:
[1] 2 4 6 [1] -21



