Created
May 27, 2012 04:56
-
-
Save doobwa/2802225 to your computer and use it in GitHub Desktop.
Create named lists quickly in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##' 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