Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

functions
r
communitycreator

How to use the length() function to get the length of a list in R

Onyejiaku Theophilus Chidalu

Overview

The length() function in R gets the length of a list object. In simpler terms, it finds the number of items in a list.

Syntax

length(x)

Parameter value

The length() function takes a list object as its single parameter value.

Return value

The length() function returns the list object’s length passed to it.

Code example

In the code below, we use the length() function to determine a list’s length:

# creating a list
mylist <- list(1, 2, 3, 4, 5)

# using the length function 
length(mylist)
Implementing the length() function

Code explanation

We use the length() function in the code above to determine the number of items in the list variable my_variable. This returns 5.

RELATED TAGS

functions
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring