[R] Assigning several lists to variables whose names are contained in other variables
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Sat Apr 10 06:32:36 CEST 2021
I freely admit that I do not understand what you mean. But it sounds like
you are trying to make things more complicated than necessary.
Perhaps this little example may help clarify the issues:
> a <- 1; b <- 2; d <- c(3,5)
> stuff <- lapply(list(a,b,d),function(x)x^2)
> stuff
[[1]]
[1] 1
[[2]]
[1] 4
[[3]]
[1] 9 25
> stuff[[3]]
[1] 9 25
Note that one may apply (almost) any function that returns objects (and
doesn't have nasty side effects, I suppose), including graphical objects,
and store them in the list that is returned. These objects can then be
accessed as usual and manipulated/displayed/assigned ... whatever.
If this misunderstands your query and is irrelevant, do not bother to
explain. Or reply. Won't be the first time I did not get it.
If OTOH this is a complete mystery to you, then you need to spend some time
learning about R lists and how. to use them.
Cheers,
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 Fri, Apr 9, 2021 at 7:22 PM Wolfgang Grond <wgrond using wgrond.de> wrote:
> As I wrote before, I calculate tbl_graph objects, which will be joined
> afterwards. Not too much, the number of graphs to calculate is in the range
> between 5 to 20.
>
> Further steps are not automated, because they depend on how the single
> graphs look like, and which of them will be joined.
>
> For this reason I thought it would be nice to have the single tbl_ graph
> objects stored in variables having the name of the graph.
>
> For this reason I tried to find a better solution instead of assigning
> each graph by hand:
>
> subnet_MYSUBNET <- my_function(MYSUBNET)
>
> To my understanding it is therefore neccessary to assign the result of the
> function to a variable whose name consists of a fixed string and the
> content of a further variable.
>
> That was the intention for me to ask.
>
> Am 9. April 2021 17:22:05 MESZ schrieb David Winsemius <
> dwinsemius using comcast.net>:
> >
> >On 4/9/21 5:21 AM, Wolfgang Grond wrote:
> >> Greg,
> >>
> >> here I get the error message:
> >>
> >> Error my_function(val) :
> >>
> >> cannot find function my_function.
> >
> >I'm guessing that you are following someone else's blog and have failed
> >
> >one of two things:
> >
> >- understand that what was meant by the author was that you were
> >assumed
> >to have a function in mind to use for a programming strategy being
> >illustrated
> >
> >- or you were copying and pasting only part of a blog and failed to
> >paste in the code from above where there was earlier code defining
> >`my_function`
> >
> >>
> >> Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall
> ><minshall using umich.edu>:
> >>> Wolfgang,
> >>>
> >>>> result <- assign(paste("subnet_", val, sep = "")
> >>>>
> >>>> result <- my_function(val)
> >>> i don't understand why you are twice assigning to =result=. also,
> >the
> >>> first assignment doesn't seem well formatted (t's missing a value?).
> >>>
> >>> did you mean something like
> >>>
> >>> : assign(paste("subnet_", val, sep = ""), my_function(val))
> >>>
> >>> (which i would think should work)?
> >>>
> >>> cheers, Greg
> >>>
> >>> ______________________________________________
> >>> R-help using 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.
> >>
> >> -
> >> Numberland - Dr. Wolfgang Grond
> >> Diplomphysiker, TQM-Assessor (EFQM)
> >> Six Sigma Green Belt
> >> Ingenieurbüro / Engineering Consultancy
> >> Lohfeld 20, DE-95326 Kulmbach, Germany
> >> Phone: +49 9221 6919131
> >> Fax: +49 9221 6919156
> >> Mail: grond using numberland.com
> >> URL: http://www.numberland.com
> >> [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help using 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 using 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.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list