Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread Alan Yong
Much thanks, Hadley! Cheers, Alan On Jan 29, 2015, at 12:36 PM, Hadley Wickham wrote: > On Thu, Jan 29, 2015 at 11:43 AM, Alan Yong wrote: >> Much thanks to everyone for their recommendations! I agree that fishing in >> the global environment isn't ideal & only shows my budding understanding

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread Hadley Wickham
On Thu, Jan 29, 2015 at 11:43 AM, Alan Yong wrote: > Much thanks to everyone for their recommendations! I agree that fishing in > the global environment isn't ideal & only shows my budding understanding of R. > > For now, I will adapt Chel Hee's "length(eval(parse(text=DFName))[,1])" > solution

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread Alan Yong
Much thanks to everyone for their recommendations! I agree that fishing in the global environment isn't ideal & only shows my budding understanding of R. For now, I will adapt Chel Hee's "length(eval(parse(text=DFName))[,1])" solution then fully explore Jeff's suggestion to put the data frames

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread David L Carlson
ubject: Re: [R] Passing a Data Frame Name as a Variable in a Function I like Jeff's comments on the previous post. Regarding Alan's question, please see the following example. > df.1 <- data.frame(v1=1:5, v2=letters[1:5]) > df.2 <- data.frame(v1=LETTERS[1:3], v2=11:13) >

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread Chel Hee Lee
I like Jeff's comments on the previous post. Regarding Alan's question, please see the following example. > df.1 <- data.frame(v1=1:5, v2=letters[1:5]) > df.2 <- data.frame(v1=LETTERS[1:3], v2=11:13) > DFName <- ls(pattern = glob2rx("df.*"))[1] > DFName [1] "df.1" > length(DFName[,1]) Error in D

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread peter dalgaard
On 29 Jan 2015, at 07:34 , Jeff Newmiller wrote: > This approach is fraught with dangers. > > I recommend that you put all of those data frames into a list and have your > function accept the list and the name and use the list indexing operator > mylist[[DFName]] to refer to it. Having functi

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-28 Thread Jeff Newmiller
This approach is fraught with dangers. I recommend that you put all of those data frames into a list and have your function accept the list and the name and use the list indexing operator mylist[[DFName]] to refer to it. Having functions that go fishing around in the global environment will be