列出 R 编程中当前工作目录中存在的所有对象 - ls()函数
R 语言中的ls()
函数用于列出工作目录中存在的所有对象的名称。
Syntax: ls()
Parameters:
This function needs no argument
示例 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"
示例 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"