Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Evaluate an Expression in R Programming – eval() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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
My Personal Notes arrow_drop_up
Last Updated : 19 Jun, 2020
Like Article
Save Article
Similar Reads