The length()
function in R gets the length of a list object.
In simpler terms, it finds the number of items in a list.
length(x)
The length()
function takes a list object as its single parameter value.
The length()
function returns the list object’s length passed to it.
In the code below, we use the length()
function to determine a list’s length:
# creating a listmylist <- list(1, 2, 3, 4, 5)# using the length functionlength(mylist)
We use the length()
function in the code above to determine the number of items in the list variable my_variable
. This returns 5
.