R – List Length
To get length of list in R programming, call length()
function and pass the list as argument to length function.
The syntax to call length function with list myList
as argument is
length(myList)
The length function returns an integer representing the number of items in the list.
Examples
In the following program, we will create a list containing some string values and find its length programmatically using length()
function.
example.R
myList <- list("Sunday", "Monday", "Tuesday", "Wednesday") listLength = length(myList) cat("List length is :", listLength)
Output
List length is 4
Now, let us create an empty list and verify if the list’s length is zero or not.
example.R
myList <- list() listLength = length(myList) cat("List length is :", listLength)
Output
List length is : 0
Conclusion
In this R Tutorial, we learned how to find the length of a list in R programming using length() function, with the help of examples.