To get a sublist in R, you can use the indexing operator []
to specify the range of elements.
In this example,
my_list
with some elements.[]
to get a sublist from my_list
. The operator takes a vector of indices specifying the elements to include in the sublist.my_list <- list(1, 2, 3, 4, 5)
sub_list <- my_list[2:4]
print(paste('Sublist:', toString(sub_list)))
Sublist: 2, 3, 4
In this example,
my_list
with some elements.[]
to get a sublist from my_list
by specifying different start and end indices.my_list <- list(10, 20, 30, 40, 50, 60)
sub_list <- my_list[3:5]
print(paste('Sublist:', toString(sub_list)))
Sublist: 30, 40, 50
In this tutorial, we learned How to get Sub List in R language with well detailed examples.