R语言 把表达式转换成字符串 – deparse()函数

R语言 把表达式转换成字符串 – deparse()函数

R语言中的 deparse() 函数用于将表达式类的对象转换为字符类的对象。

语法: deparse(expr)

参数:

expr: 表达式类的对象

示例 1 :

# R program to convert 
# expression to character
  
# Creating an object of expression class
x <- expression(sin(pi / 2))
  
# Class of object
class(x)
  
# Calling deparse() Function
x1 <- deparse(x)
  
# Class of parsed object
class(x1)

输出

[1] "expression"
[1] "character"

例2 :

# R program to convert 
# expression to character
  
# Creating an object of expression class
x <- expression(2 ^ 3)
  
# Evaluating the value of object
eval(x)
  
# Calling deparse() Function
x1 <- deparse(x)
  
# Evaluating the value of object
eval(x1)

输出

[1] 8
[1] "expression(2^3)"

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程