Here we go again: append an element to a list in R

后端 未结 3 1526
甜味超标
甜味超标 2020-12-07 10:44

I am not happy with the accepted answer to Append an object to a list in R in amortized constant time?

> list1 <- list(\"foo\", pi)
> bar <- list         


        
3条回答
  •  盖世英雄少女心
    2020-12-07 10:56

    Operations that change the length of a list/vector in R always copy all the elements into a new list, and so will be slow, O(n). Storing in an environment is O(1) but has a higher constant overhead. For an actual O(1) append and benchmark comparison of a number of approaches see my answer to the other question at https://stackoverflow.com/a/32870310/264177.

提交回复
热议问题