Re: [R] Dynamic string as element name in a list

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 27 Mar 2008 10:52:19 -0300

Try this:

foo <- function(x)
{
clipname <- "LK"
out <- list()

out[[clipname]] <- rnorm(5)
return(out)
}

On 27/03/2008, Paul Lemmens <paul.lemmens_at_gmail.com> wrote:
> Dear all,
>
> I have a piece of code along the lines of
>
> f <- function(x) {
> clipname <- "LK" # but is in real determined based on info in data.frame x
> # other manipulations
> return( list(clipname=list(....)))
> }
>
> My intention is to do
>
> out <- f(dat)
>
> and then (in this example) having/getting
>
> out$LK
>
> which is a list in itself.
>
>
> Of course, it doesn't work like this, but having tried all kinds of
> combinations of eval(), parse(), substitute(), and friends I was
> unable to get the contents of clipname as the element name of the list
> that I return in f().
>
> Is this possible to do so at all and if so, what am I missing?
>
>
> Kind regards,
> Paul Lemmens
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Thu 27 Mar 2008 - 18:05:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Mar 2008 - 18:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive