R语言 搜索并返回具有指定名称的对象 – get() 函数

R语言 搜索并返回具有指定名称的对象 – get() 函数

R语言中的 get() 函数用于返回一个具有函数参数指定名称的对象。这是另一种打印对象值的方法,就像打印函数一样。这个函数也可以用来将一个对象复制到另一个对象。

语法: get(object)

参数:

对象: 向量、数组、列表等。

例子 1 :

# R program to illustrate 
# the use of get() Function
  
# Creating vectors
x1 <- c("abc", "cde", "def")
x2 <- c(1, 2, 3)
x3 <- c("M", "F")
  
# Calling get() Function
# for print operation
get("x2")
  
# Assigning to another vector
x4 <- get("x3")
print(x4)
R

输出

[1] 1 2 3
[1] "M" "F"
R

例2 :

# R program to illustrate 
# the use of get() Function
  
# Creating vectors
x1 <- c("abc", "cde", "def")
x2 <- c(1, 2, 3)
  
# Creating a list of vectors
list1 <- list(x1, x2) 
  
# Calling get() Function
# for print operation
get("list1")
R

输出

[[1]]
[1] "abc" "cde" "def"

[[2]]
[1] 1 2 3
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册