Quantcast
Channel: Append an object to a list in R in amortized constant time, O(1)? - Stack Overflow
Viewing all articles
Browse latest Browse all 18

Answer by doug for Append an object to a list in R in amortized constant time, O(1)?

$
0
0

This is a straightforward way to add items to an R List:

# create an empty list:small_list = list()# now put some objects in it:small_list$k1 = "v1"small_list$k2 = "v2"small_list$k3 = 1:10# retrieve them the same way:small_list$k1# returns "v1"# "index" notation works as well:small_list["k2"]

Or programmatically:

kx = paste(LETTERS[1:5], 1:5, sep="")vx = runif(5)lx = list()cn = 1for (itm in kx) { lx[itm] = vx[cn]; cn = cn + 1 }print(length(lx))# returns 5

Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>