Return All Data Objects in Workspace in R (2 Examples)
This tutorial illustrates how to return all data objects in the global environment in the R programming language.
Creating Example Data
data(iris) # Create some data objects iris <- iris[1:5, ] x1 <- letters[1:5] x2 <- 6:1 |
data(iris) # Create some data objects iris <- iris[1:5, ] x1 <- letters[1:5] x2 <- 6:1
Example 1: Return Names of Data Objects in Workspace
ls() # Display names # [1] "iris" "x1" "x2" |
ls() # Display names # [1] "iris" "x1" "x2"
Example 2: Return Content of Data Objects in Workspace
mget(ls()) # Display content # $iris # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # # $x1 # [1] "a" "b" "c" "d" "e" # # $x2 # [1] 6 5 4 3 2 1 |
mget(ls()) # Display content # $iris # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # # $x1 # [1] "a" "b" "c" "d" "e" # # $x2 # [1] 6 5 4 3 2 1
Further Resources
Furthermore, you may read some of the other articles on my website. I have released numerous posts on topics such as factors, missing data, and vectors: