[R] Treating a vector of characters as object names to create list

Dénes Tóth toth.denes at ttk.mta.hu
Mon Sep 5 01:13:56 CEST 2016



On 09/05/2016 12:07 AM, Bert Gunter wrote:
> Time for an R tutorial or two to learn how to use the "apply" family
> in R. I think what you want is:
>
> merged_list <- lapply(merging, get)
>

Or even:
named_merged_list <- mget(merging)

Anyway, probably you could arrive to a list of parameters directly. 
(E.g., if you import the parameter values from an external source or if 
they are the return values of a function, etc.).

>
> -- Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Sep 4, 2016 at 2:57 PM, Ryan Utz <utz.ryan at gmail.com> wrote:
>> Hello,
>>
>> I have a vector of characters that I know will be object names and I'd like
>> to treat this vector as a series of names to create a list. But, for the
>> life of me, I cannot figure out how to treat a vector of characters as a
>> vector of object names when creating a list.
>>
>> For example, this does exactly what I want to do (with 'merged.parameters'
>> as the end goal):
>>
>> ###
>> merging=c('alkalinity','iron')
>> alkalinity=c('39086','29801','90410','00410')
>> iron=c('01045','01046')
>> merged.parameters=list(alkalinity,iron)
>> ###
>>
>> But, say I have many, many parameters in 'merging' beyond alkalinity and
>> iron and I'd like to just cleanly turn the elements in 'merging' into a
>> list. This does not work:
>>
>> ###
>> merged.parameters=list(get(merging))
>> ###
>>
>> because it's only grabbing the first element of 'merging', for some reason.
>> Any advice? This feels like it really should be easy...
>>
>> --
>>
>> Ryan Utz, Ph.D.
>> Assistant professor of water resources
>> *chatham**UNIVERSITY*
>> Home/Cell: (724) 272-7769
>>
>>          [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list