Open In App

Evaluate an Expression in R Programming – eval() Function

Last Updated : 19 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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() Function
eval(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 vector
x <- c(1, 2, 3)
  
# Creating a matrix
mat <- matrix(c(2, 7, 5, 7), 2)
  
# Calling eval() function
eval(x * 2)
eval(det(mat))


Output:

[1] 2 4 6
[1] -21

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads