Warning: session_start(): open(/tmp/sess_4b7deb6f186a0ee3627cafc18d656543, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
ls() function in R: How To List Objects In R - LearnShareIT

ls() function in R: How To List Objects In R

In this tutorial, we will share with you the usage, the syntax, and how to use the ls() function in R. The ls() function can help you list the objects in your R environment. Follow us to learn more about the ls() function with the explanation and examples below.

Ls() Function In R

What does the ls() function do in R?

The ls() function in R helps you list the objects in your R environment. This function will return the vector of the character Strings, which are the names of the object in your R environment. You can list the specified objects by assigning the value to the parameters of the ls() function. Let’s take a look at the syntax of the ls() function in R.

Syntax

ls(name, pos, envir, all.names, pattern, sorted)

Parameters

  • name: The name of the environment to be listed objects.
  • pos: The alternative argument of the ‘name’ parameter.
  • envir: Another alternative argument of the ‘name’ parameter.
  • all.names: Logical. The default is FALSE. List the objects whose name starts with a dot or not.
  • pattern: List the objects whose names match the specified pattern.
  • sorted: Logical. The default is TRUE. If TRUE, the result as the vector of character Strings will be sorted alphabetically.

After learning the usage and the syntax of the ls() function in R, you will learn how to use it in the next title below.

How To Use The Ls() Function In R

The ls() function is used to list the specified objects in the specified R environment. You can customize the result of this function by changing the value of its parameters.

Use the ls() function to list all objects in R environment

You can use the ls() function to list all objects. Simply, you only need to use the default syntax of the ls() function.

Look at the example below.

# Create a vector
vec <- c("LearnShareIT", 3, 4, 5)

# Create a data frame
df <- data.frame(festivals = c("Halloween", "Christmas"))

# Create a character String
.hidden <- "LearnShareIT"

# List all objects
ls()

Output

[1] "df" "vec"

As you can see, the ‘.hidden’ object is not listed. This problem happens because the ls() function does not list the object whose name starts with a dot. 

List all objects even if its name start with a dot

As you can see in the previous title, the ‘.hidden’ object is not listed. This problem happens because the ls() function does not list the object whose name starts with a dot. To handle that, you must assign the value TRUE to the ‘all.names’ parameter.

Look at the example below.

# Create a vector
vec <- c("LearnShareIT", 3, 4, 5)

# Create a data frame
df <- data.frame(festivals = c("Halloween", "Christmas"))

# Create the hidden object
.hidden <- "LearnShareIT"

# List all objects
ls(all.names = TRUE)

Output

[1] ".hidden" "df" "vec" 

List objects that satisfy the specified pattern

You can use the ls() function to list objects that satisfy the specified pattern by assigning the value to the ‘pattern’ parameters.

Look at the example below.

# Create a vector
vec <- c("LearnShareIT", 3, 4, 5)

# Create a data frame
df <- data.frame(festivals = c("Halloween", "Christmas"))

# Create the hidden object
.hidden <- "LearnShareIT"

# List objects whose names contain an v
ls(all.names = TRUE, pattern = "v")

Output

[1] "vec"

Besides the ls() function, you can learn the series of R tutorials here.

Summary

You have learned the definition, and how to use the ls() function in R. You can use the ls() function to list the specified objects in the specified environment. We hope this tutorial is helpful to you. Thanks!

Posted in R

Leave a Reply

Your email address will not be published. Required fields are marked *