Select multiple elements from a list

前端 未结 1 1001
死守一世寂寞
死守一世寂寞 2020-12-23 23:50

I have a list in R some 10,000 elements long. Say I want to select only elements, 5, 7, and 9. I\'m not sure how I would do that without a for loop.

I want to do som

相关标签:
1条回答
  • 2020-12-24 00:34

    mylist[c(5,7,9)] should do it.

    You want the sublists returned as sublists of the result list; you don't use [[]] (or rather, the function is [[) for that -- as Dason mentions in comments, [[ grabs the element.

    0 讨论(0)
提交回复
热议问题