To get the length of a list in R, you can use the length()
function.
In this example,
numbers
with integer values.length()
function to get the number of elements in the list numbers
.length()
function returns the number of elements in the list.numbers <- list(1, 2, 3, 4, 5)
length_of_list <- length(numbers)
cat("Length of the list is:", length_of_list)
Length of the list is: 5
In this example,
fruits
with string values.length()
function to get the number of elements in the list fruits
.length()
function returns the number of elements in the list.fruits <- list("apple", "banana", "cherry")
length_of_list <- length(fruits)
cat("Length of the list is:", length_of_list)
Length of the list is: 3
In this tutorial, we learned How to Get Length of a List in R language with well detailed examples.