Re: [R] subsetting with column name as string

2008-08-06 Thread Dan Davison
On Wed, Aug 06, 2008 at 11:53:25AM -0400, Faheem Mitha wrote: > > Hi, > > Consider the following > >> x = c(1,2) >> y = c(3,4) >> d = data.frame(cbind(x,y)) >> d$x > [1] 1 2 >> d$"x" > [1] 1 2 >> >> foo = function(val) > + { > + return(d$val) > + } >> >> bar = function() > + { > + return(d$"x")

Re: [R] subsetting with column name as string

2008-08-06 Thread Prof Brian Ripley
On Wed, 6 Aug 2008, Faheem Mitha wrote: Hi, Consider the following x = c(1,2) y = c(3,4) d = data.frame(cbind(x,y)) d$x [1] 1 2 d$"x" [1] 1 2 foo = function(val) + { + return(d$val) + } bar = function() + { + return(d$"x") + } foo("x") NULL bar() [1] 1 2 I'm a little surpr

Re: [R] subsetting with column name as string

2008-08-06 Thread Faheem Mitha
On Wed, 6 Aug 2008, milton ruser wrote: Try this foo1 = function(val) { return(d[val]) } foo1("x") Thanks for the suggestion. I appreciate it. My original question wasn't just a pragmatic "how do I do this" type question. I was also wondering about the language issues involved.

Re: [R] subsetting with column name as string

2008-08-06 Thread milton ruser
Try this foo1 = function(val) { return(d[val]) } foo1("x") Good luck miltinho astronauta brazil On 8/6/08, Faheem Mitha <[EMAIL PROTECTED]> wrote: > > > Hi, > > Consider the following > > x = c(1,2) >> y = c(3,4) >> d = data.frame(cbind(x,y)) >> d$x >> > [1] 1 2 > >> d$"x" >> > [1] 1