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
The length function returns an integer representing the number of items in the list.
In the following program, we will create a list containing some string values and find its length programmatically using
myList <- list("Sunday", "Monday", "Tuesday", "Wednesday") listLength = length(myList) cat("List length is :", listLength)
List length is 4
Now, let us create an empty list and verify if the list’s length is zero or not.
myList <- list() listLength = length(myList) cat("List length is :", listLength)
List length is : 0
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.