[R] Dynamic string as element name in a list
Paul Lemmens
paul.lemmens at gmail.com
Thu Mar 27 15:10:58 CET 2008
Hi Henrique,
On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna <wwwhsd at gmail.com> wrote:
> Try this:
>
> foo <- function(x)
> {
> clipname <- "LK"
> out <- list()
> out[[clipname]] <- rnorm(5)
> return(out)
> }
That easy ... Hadn't thought of it. But now I have a refinement in foo()
foo <- function(x) {
out <- list()
lapply(x$clipno, function(c) {
clipname <- x$clipname
# stuff
out[[clipname]] <- rnorm(5)
})
return(out)
}
But this returns the/an empty list?
Best regards,
Paul Lemmens
More information about the R-help
mailing list