在 R 编程中创建表达式 - expression()函数
R 语言中的expression()
函数用于根据作为参数传递的值创建表达式。它创建一个表达式类的对象。
Syntax: expression(character)
Parameters:
character: Expression, like calls, symbols, constants
示例 1:
# R program to create an expression
# Calling expression() Function
x <- expression(2 ^ 3)
x
# Printing value of the expression
eval(x)
输出:
expression(2^3)
[1] 8
示例 2:
# R program to create an expression
# Calling expression() Function
x <- expression(sin(pi / 2))
x
# Printing value of the expression
eval(x)
# Printing class of expression
class(x)
输出:
expression(sin(pi/2))
[1] 1
[1] "expression"