Efficiently adding or removing elements to a vector or list in R?

前端 未结 4 794
予麋鹿
予麋鹿 2020-12-31 06:22

I\'m implementing an algorithm that involves lots of adding and removing things from sets. In R, this is slow because as far as I know, adding or removing things from a vect

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 07:03

    Chapter 2 of The R Inferno has some interesting comments on this, including perdiodic growing objects to reduce memory fragmentation and allocation overhead.

    If you know what the ultimate size of the set is, then the method you suggest is probably the best - ie subset from the whole universe using an approprate membership vector. Difficult to know whats best without seeing exactly what you are trying to do though.

提交回复
热议问题