📜  在 R 编程中创建模式调用对象 - call()函数

📅  最后修改于: 2022-05-13 01:55:10.055000             🧑  作者: Mango

在 R 编程中创建模式调用对象 - call()函数

R 语言中的call()函数用于创建或测试“call”模式的对象。

示例 1:

# R program to illustrate
# call function
  
# Calling call() function
x <- call("sin", 23)
y <- call("cos", 0)
x
y
  
# Evaluating values of call
eval(x)
eval(y)

输出:

sin(23)
cos(0)
[1] -0.8462204
[1] 1

示例 2:

# R program to illustrate
# call function
  
# Calling call() function
x <- call("round", 10.5)
x 
  
# Initializing a round character
f <- "round"
  
# Calling call() function
call(f, quote(A)) 

输出:

round(10.5)
round(A)

示例 3:

# R program to illustrate
# call function
  
# Initializing round value
# without its character
f <- round
  
# Calling call() function
# which will give an error
# bcs the argument should be
# a character string
call(f, quote(A))

输出:

Error in call(f, quote(A)) : first argument must be a character string
Execution halted