On Tue, 2 Nov 2021 at 10:48, Yonghua Peng <y...@pobox.com> wrote: > > I know this is a newbie question. But how do I implement the hash structure > which is available in other languages (in python it's dict)? >
As other posters wrote then environments are the solution. data.frames, vectors and lists are much slower and less useful to use as key-value pairs. Here are some code I somethings uses: cache <- NULL cache_set <- function(key, value) { assign(key, value, envir = cache) } cache_reset <- function() { cache <<- new.env(TRUE, emptyenv()) } cache_get <- function(key) { get(key, envir = cache, inherits = FALSE) } cache_has_key <- function(key) { exists(key, envir = cache, inherits = FALSE) } cache_reset() [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.