Search and Return an Object with the specified name in R Programming – get() Function

get() function in R Language is used to return an object with the name specified as argument to the function. This is another method of printing values of the objects just like print function. This function can also be used to copy one object to another.

Syntax: get(object)

Parameters:
object: Vector, array, list, etc.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

[[2]]
[1] 1 2 3

My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.