Skip to content

Instantly share code, notes, and snippets.

@piccolbo
Last active December 17, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piccolbo/5616152 to your computer and use it in GitHub Desktop.
Save piccolbo/5616152 to your computer and use it in GitHub Desktop.
Assignment to R named arrays is quadratic (when extending at the same time)
name.me = c()
system.time({name.me[as.character(1:10^3)] = T})
# user system elapsed
# 0.004 0.000 0.004
system.time({name.me[as.character(1:10^4)] = T})
# user system elapsed
# 0.369 0.000 0.369
system.time({name.me[as.character(1:10^5)] = T})
# user system elapsed
# 48.187 0.055 48.235
system.time({name.me[as.character(1:10^5)] = F})
# user system elapsed
# 0.033 0.001 0.035
@piccolbo
Copy link
Author

In one word: avoid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment