Quantcast

Creating named lists

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Creating named lists

Rune Schjellerup Philosof
I often find myself making lists similar to this
list(var1=var1, var2=var2)

It doesn't seem list has an option, to make it use the name of the
variable as name in the list.
Is there another function that does this?

--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Linlin Yan
Did you mean this:

> n <- c('a', 'b')
> structure(list(1, 2), names = n)
$a
[1] 1

$b
[1] 2


On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
<[hidden email]> wrote:

> I often find myself making lists similar to this
> list(var1=var1, var2=var2)
>
> It doesn't seem list has an option, to make it use the name of the
> variable as name in the list.
> Is there another function that does this?
>
> --
> Med venlig hilsen
>
> Rune Schjellerup Philosof
> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>
> Telefon: 6550 3607
> E-mail:  [hidden email]
> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>
> SYDDANSK UNIVERSITET
> _______________________________________________________________
> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Rune Schjellerup Philosof
No, I mean this:
a <- 1
b <- 2
list(a=a, b=b)

I just find it anoying, that I have to type the names of the variables
twice.
I would like something like this instead:
list(a, b, use.var.names=TRUE)

--
Rune

Linlin Yan wrote:

> Did you mean this:
>
>  
>> n <- c('a', 'b')
>> structure(list(1, 2), names = n)
>>    
> $a
> [1] 1
>
> $b
> [1] 2
>
>
> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
> <[hidden email]> wrote:
>  
>> I often find myself making lists similar to this
>> list(var1=var1, var2=var2)
>>
>> It doesn't seem list has an option, to make it use the name of the
>> variable as name in the list.
>> Is there another function that does this?
>>
>> --
>> Med venlig hilsen
>>
>> Rune Schjellerup Philosof
>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>
>> Telefon: 6550 3607
>> E-mail:  [hidden email]
>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>
>> SYDDANSK UNIVERSITET
>> _______________________________________________________________
>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>>    
--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk


        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Gesmann, Markus
I think, you are looking for ?llist in the package Hmisc.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Rune Schjellerup Philosof
Sent: 12 March 2010 09:46
To: Linlin Yan
Cc: [hidden email]
Subject: Re: [R] Creating named lists

No, I mean this:
a <- 1
b <- 2
list(a=a, b=b)

I just find it anoying, that I have to type the names of the variables twice.
I would like something like this instead:
list(a, b, use.var.names=TRUE)

--
Rune

Linlin Yan wrote:

> Did you mean this:
>
>  
>> n <- c('a', 'b')
>> structure(list(1, 2), names = n)
>>    
> $a
> [1] 1
>
> $b
> [1] 2
>
>
> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
> <[hidden email]> wrote:
>  
>> I often find myself making lists similar to this list(var1=var1,
>> var2=var2)
>>
>> It doesn't seem list has an option, to make it use the name of the
>> variable as name in the list.
>> Is there another function that does this?
>>
>> --
>> Med venlig hilsen
>>
>> Rune Schjellerup Philosof
>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>
>> Telefon: 6550 3607
>> E-mail:  [hidden email]
>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>
>> SYDDANSK UNIVERSITET
>> _______________________________________________________________
>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>>    

--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk


        [[alternative HTML version deleted]]

**********************************************************************
The information in this E-Mail and in any attachments is...{{dropped:27}}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Erich Neuwirth
In reply to this post by Rune Schjellerup Philosof
If thats what you want, why don't you do
list(a=1, b=2)


On 3/12/2010 10:45 AM, Rune Schjellerup Philosof wrote:

> No, I mean this:
> a <- 1
> b <- 2
> list(a=a, b=b)
>
> I just find it anoying, that I have to type the names of the variables
> twice.
> I would like something like this instead:
> list(a, b, use.var.names=TRUE)
>
> --
> Rune
>
> Linlin Yan wrote:
>> Did you mean this:
>>
>>  
>>> n <- c('a', 'b')
>>> structure(list(1, 2), names = n)
>>>    
>> $a
>> [1] 1
>>
>> $b
>> [1] 2
>>
>>
>> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
>> <[hidden email]> wrote:
>>  
>>> I often find myself making lists similar to this
>>> list(var1=var1, var2=var2)
>>>
>>> It doesn't seem list has an option, to make it use the name of the
>>> variable as name in the list.
>>> Is there another function that does this?
>>>
>>> --
>>> Med venlig hilsen
>>>
>>> Rune Schjellerup Philosof
>>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>>
>>> Telefon: 6550 3607
>>> E-mail:  [hidden email]
>>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>>
>>> SYDDANSK UNIVERSITET
>>> _______________________________________________________________
>>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>>    
>
>
>
> ______________________________________________
> [hidden email] 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.

--
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Rune Schjellerup Philosof
Because I was simplifying the use case to make an example.
The variables are often created during various computations in functions
and in order to return more than one value from a function I have to
create a list.
Wrapping everything in a list statement would make it harder to read and
make debugging a pain.


Erich Neuwirth wrote:

> If thats what you want, why don't you do
> list(a=1, b=2)
>
>
> On 3/12/2010 10:45 AM, Rune Schjellerup Philosof wrote:
>  
>> No, I mean this:
>> a <- 1
>> b <- 2
>> list(a=a, b=b)
>>
>> I just find it anoying, that I have to type the names of the variables
>> twice.
>> I would like something like this instead:
>> list(a, b, use.var.names=TRUE)
>>
>> --
>> Rune
>>
>> Linlin Yan wrote:
>>    
>>> Did you mean this:
>>>
>>>  
>>>      
>>>> n <- c('a', 'b')
>>>> structure(list(1, 2), names = n)
>>>>    
>>>>        
>>> $a
>>> [1] 1
>>>
>>> $b
>>> [1] 2
>>>
>>>
>>> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
>>> <[hidden email]> wrote:
>>>  
>>>      
>>>> I often find myself making lists similar to this
>>>> list(var1=var1, var2=var2)
>>>>
>>>> It doesn't seem list has an option, to make it use the name of the
>>>> variable as name in the list.
>>>> Is there another function that does this?
>>>>
>>>> --
>>>> Med venlig hilsen
>>>>
>>>> Rune Schjellerup Philosof
>>>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>>>
>>>> Telefon: 6550 3607
>>>> E-mail:  [hidden email]
>>>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>>>
>>>> SYDDANSK UNIVERSITET
>>>> _______________________________________________________________
>>>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>>>
>>>>    
>>>>        
>>
>> ______________________________________________
>> [hidden email] 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.
>>    
>
>  
--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk


        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Miguel Porto
Hi
See if this function works for you (I didn't properly test it...):

nlist=function(...) {
    a=list(...);
    names(a)=as.character(match.call()[2:(length(a)+1)])
    return(a);
}

Ex:

> a=1:3
> b=matrix(1:10,nc=2)
> nlist(a,b)
$a
[1] 1 2 3

$b
     [,1] [,2]
[1,]    1    6
[2,]    2    7
[3,]    3    8
[4,]    4    9
[5,]    5   10

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Søren Højsgaard
In reply to this post by Rune Schjellerup Philosof
Rune,
I doubt that this is possible because R-objects will typically not know "their own name".


Med venlig hilsen / Regards
Søren Højsgaard


-----Oprindelig meddelelse-----
Fra: [hidden email] [mailto:[hidden email]] På vegne af Rune Schjellerup Philosof
Sendt: 12. marts 2010 10:46
Til: Linlin Yan
Cc: [hidden email]
Emne: Re: [R] Creating named lists

No, I mean this:
a <- 1
b <- 2
list(a=a, b=b)

I just find it anoying, that I have to type the names of the variables twice.
I would like something like this instead:
list(a, b, use.var.names=TRUE)

--
Rune

Linlin Yan wrote:

> Did you mean this:
>
>  
>> n <- c('a', 'b')
>> structure(list(1, 2), names = n)
>>    
> $a
> [1] 1
>
> $b
> [1] 2
>
>
> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
> <[hidden email]> wrote:
>  
>> I often find myself making lists similar to this list(var1=var1,
>> var2=var2)
>>
>> It doesn't seem list has an option, to make it use the name of the
>> variable as name in the list.
>> Is there another function that does this?
>>
>> --
>> Med venlig hilsen
>>
>> Rune Schjellerup Philosof
>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>
>> Telefon: 6550 3607
>> E-mail:  [hidden email]
>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>
>> SYDDANSK UNIVERSITET
>> _______________________________________________________________
>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>>    

--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Rune Schjellerup Philosof
It is possible.
Miguel Porto gave a fine example.


Søren Højsgaard skrev:

> Rune,
> I doubt that this is possible because R-objects will typically not know "their own name".
>
>
> Med venlig hilsen / Regards
> Søren Højsgaard
>
>
> -----Oprindelig meddelelse-----
> Fra: [hidden email] [mailto:[hidden email]] På vegne af Rune Schjellerup Philosof
> Sendt: 12. marts 2010 10:46
> Til: Linlin Yan
> Cc: [hidden email]
> Emne: Re: [R] Creating named lists
>
> No, I mean this:
> a <- 1
> b <- 2
> list(a=a, b=b)
>
> I just find it anoying, that I have to type the names of the variables twice.
> I would like something like this instead:
> list(a, b, use.var.names=TRUE)
>
> --
> Rune
>
> Linlin Yan wrote:
>  
>> Did you mean this:
>>
>>  
>>    
>>> n <- c('a', 'b')
>>> structure(list(1, 2), names = n)
>>>    
>>>      
>> $a
>> [1] 1
>>
>> $b
>> [1] 2
>>
>>
>> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
>> <[hidden email]> wrote:
>>  
>>    
>>> I often find myself making lists similar to this list(var1=var1,
>>> var2=var2)
>>>
>>> It doesn't seem list has an option, to make it use the name of the
>>> variable as name in the list.
>>> Is there another function that does this?
>>>
>>> --
>>> Med venlig hilsen
>>>
>>> Rune Schjellerup Philosof
>>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>>
>>> Telefon: 6550 3607
>>> E-mail:  [hidden email]
>>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>>
>>> SYDDANSK UNIVERSITET
>>> _______________________________________________________________
>>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>>    
>>>      
>
> --
> Med venlig hilsen
>
> Rune Schjellerup Philosof
> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>
> Telefon: 6550 3607
> E-mail: [hidden email]
> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>
> SYDDANSK UNIVERSITET
> _______________________________________________________________
> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>
>
> [[alternative HTML version deleted]]
>
>  

--
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail: [hidden email]
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk


        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Duncan Murdoch
In reply to this post by Søren Højsgaard
On 12/03/2010 7:20 AM, Søren Højsgaard wrote:
> Rune,
> I doubt that this is possible because R-objects will typically not know "their own name".
>  

Objects don't know their own name, but functions can find out everything
about how they were called.  So something like this would come close:

mylist <- function(..., use.var.names=FALSE) {
  vals <- list(...)
  if (use.var.names) {
    names <- names(vals)
    call <- sys.call()
    skip <- 1
    for (i in 2:length(call)) {
      if (names(call)[i] == "use.var.names") skip <- 2
      else if (names(call)[i] == "")
        names[i-skip] <- deparse(call[[i]])
    }
    names(vals) <- names
  }
  vals
}
   
I haven't tested it much, so it probably has bugs.

Duncan Murdoch

>
> Med venlig hilsen / Regards
> Søren Højsgaard
>
>
> -----Oprindelig meddelelse-----
> Fra: [hidden email] [mailto:[hidden email]] På vegne af Rune Schjellerup Philosof
> Sendt: 12. marts 2010 10:46
> Til: Linlin Yan
> Cc: [hidden email]
> Emne: Re: [R] Creating named lists
>
> No, I mean this:
> a <- 1
> b <- 2
> list(a=a, b=b)
>
> I just find it anoying, that I have to type the names of the variables twice.
> I would like something like this instead:
> list(a, b, use.var.names=TRUE)
>
> --
> Rune
>
> Linlin Yan wrote:
> > Did you mean this:
> >
> >  
> >> n <- c('a', 'b')
> >> structure(list(1, 2), names = n)
> >>    
> > $a
> > [1] 1
> >
> > $b
> > [1] 2
> >
> >
> > On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
> > <[hidden email]> wrote:
> >  
> >> I often find myself making lists similar to this list(var1=var1,
> >> var2=var2)
> >>
> >> It doesn't seem list has an option, to make it use the name of the
> >> variable as name in the list.
> >> Is there another function that does this?
> >>
> >> --
> >> Med venlig hilsen
> >>
> >> Rune Schjellerup Philosof
> >> Ph.d-stipendiat, Forskningsenheden for Biostatistik
> >>
> >> Telefon: 6550 3607
> >> E-mail:  [hidden email]
> >> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
> >>
> >> SYDDANSK UNIVERSITET
> >> _______________________________________________________________
> >> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
> >>
> >> ______________________________________________
> >> [hidden email] 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.
> >>
> >>    
>
> --
> Med venlig hilsen
>
> Rune Schjellerup Philosof
> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>
> Telefon: 6550 3607
> E-mail: [hidden email]
> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>
> SYDDANSK UNIVERSITET
> _______________________________________________________________
> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Creating named lists

Henrique Dallazuanna
In reply to this post by Rune Schjellerup Philosof
One option is this:

eapply(globalenv(), I)[c('a', 'b')]


On Fri, Mar 12, 2010 at 6:45 AM, Rune Schjellerup Philosof
<[hidden email]> wrote:

> No, I mean this:
> a <- 1
> b <- 2
> list(a=a, b=b)
>
> I just find it anoying, that I have to type the names of the variables
> twice.
> I would like something like this instead:
> list(a, b, use.var.names=TRUE)
>
> --
> Rune
>
> Linlin Yan wrote:
>> Did you mean this:
>>
>>
>>> n <- c('a', 'b')
>>> structure(list(1, 2), names = n)
>>>
>> $a
>> [1] 1
>>
>> $b
>> [1] 2
>>
>>
>> On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
>> <[hidden email]> wrote:
>>
>>> I often find myself making lists similar to this
>>> list(var1=var1, var2=var2)
>>>
>>> It doesn't seem list has an option, to make it use the name of the
>>> variable as name in the list.
>>> Is there another function that does this?
>>>
>>> --
>>> Med venlig hilsen
>>>
>>> Rune Schjellerup Philosof
>>> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>>>
>>> Telefon: 6550 3607
>>> E-mail:  [hidden email]
>>> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>>>
>>> SYDDANSK UNIVERSITET
>>> _______________________________________________________________
>>> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>>
>
> --
> Med venlig hilsen
>
> Rune Schjellerup Philosof
> Ph.d-stipendiat, Forskningsenheden for Biostatistik
>
> Telefon: 6550 3607
> E-mail:  [hidden email]
> Adresse: J.B. Winsløwsvej 9, 5000 Odense C
>
> SYDDANSK UNIVERSITET
> _______________________________________________________________
> * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Loading...