[R] Passing multiple object names to a user-defined R fn XXXX
PIKAL Petr
petr.pikal at precheza.cz
Mon Oct 14 17:31:16 CEST 2013
Hi
I will not answer your question directly but instead I have some recommendation for you. If you can put these data frames to one list object when you creates them, you can save yourself a lot of troubles.
some.list<-vector("list", n)
for (i in 1:n) {
some.list[[i]] <- some extensive computation or reading files
}
then you can use lapply/sapply/for cycle to make any computation directly on list.
I use R for more than 10 years and I do not remember any situation when I would need to create multiple objects in "n1":"nx" naming manner.
Regards
Petr
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Dan Abner
> Sent: Monday, October 14, 2013 5:10 PM
> To: r-help at r-project.org
> Subject: [R] Passing multiple object names to a user-defined R fn XXXX
>
> Hi all,
>
> I am attempting to write an R fn that will accept multiple (but varying
> on how many) objects (usually data frames) as inputs and return summary
> output.
>
> What is the best way to pass the object names to the fn (I have thought
> of
> 2 options below) AND how do I then use the names inside the fn to
> reference the actual object (I assume that I would need something like
> get(x[1]) for example to have "d1" resolve the the object d1. Correct?
>
> The 1st option I thought of was to pass the object names as a character
> vector in the call to the fn:
>
> set.matrix<-df.set(c("d1","d2","d3","d4","d5","d6","d7","d8"),by="ID")
> 2nd option: Is something like this possible:
>
> set.matrix<-df.set(c(d1,d2,d3,d4,d5,d6,d7,d8),by="ID")
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list