ls() function in R Language is used to list the names of all the objects that are present in the working directory.
Syntax: ls() Parameters: This function needs no argumentExample 1:
# R program to list all the object names
# Creating a vector
vec <- c(1, 2, 3)
# Creating a matrix
mat <- matrix(c(1:4), 2)
# Creating an array
arr <- array(c(1:4), 2)
# Calling ls() Function
ls()
[1] "arr" "mat" "vec"Example 2:
# R program to list all the object names
# Creating a list
list1 = list("Numbers" = c(1:3),
"Characters" = c(1:5))
# Creating a Data frame
df = data.frame("Numbers" = c(1:3),
"Characters" = c(4:6))
# Calling ls() Function
ls()
[1] "df" "list1"