The easiest way is to use the [ operator like:
mylist[c("listA", "listC")]
Output:
$`listA`
[1] 1 2 3 4 5 6 7 8 9 10
$listC
[1] 25 26 27 28 29 30 31 32
Note that when selecting one element from a list using [, the output might not be what we expect:
mylist["listA"]
Output:
$`listA`
[1] 1 2 3 4 5 6 7 8 9 10
> class(mylist["listA"])
[1] "list"
Here we see that selecting the element "listA" using [ does not return the element itself, but instead, returns a list that contains the "listA" element. If we want to subset the element itself by name, we should use the [[ operator:
mylist[["listA"]]
Output:
[1] 1 2 3 4 5 6 7 8 9 10
> class(mylist[["listA"]])
[1] "integer"
Another difference between [ and [[ is that [[ can only be used to select a single element. For example, the following would not work:
mylist[[c("listA", "listC")]]
Error in mylist[[c("listA", "listC")]] : subscript out of bounds
mylist[c("listA", "listC")]mylist[c("listA","listB")] = NULL