Skip to content

Instantly share code, notes, and snippets.

@doobwa
Created May 27, 2012 04:56
Show Gist options
  • Save doobwa/2802225 to your computer and use it in GitHub Desktop.
Save doobwa/2802225 to your computer and use it in GitHub Desktop.
Create named lists quickly in R
##' Quickly create a named list using one or more variables
##'
##' Example:
##' > a <- 1; b <- 2
##' > listn(a,b)
##' $a
##' [1] 1
##' $b
##' [1] 2
listn <- function(...) {
objs <- as.list(substitute(list(...)))[-1L]
nm <- as.character(objs)
v <- lapply(nm,get)
names(v) <- nm
return(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment