Related Articles

Related Articles

Evaluate an Expression in R Programming – eval() Function
  • Last Updated : 19 Jun, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to evaluate an expression
  
# Calling eval() Function
eval(sin(pi / 3))
eval(5 + 2)
eval(cos(2))

chevron_right


Output:

[1] 0.8660254
[1] 7
[1] -0.4161468

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:

[1] 2 4 6
[1] -21
My Personal Notes arrow_drop_up
Recommended Articles
Page :