Re: [R] enclosing with() in a function

2011-08-08 Thread Duncan Murdoch
On 11-08-08 9:58 PM, thmsfuller...@gmail.com wrote: On Mon, Aug 8, 2011 at 6:08 PM, peter dalgaard wrote: On Aug 9, 2011, at 00:29 , Dennis Murphy wrote: Hi: Here are a couple of ways; there may well be better ones. # (1) Use the get() function: mean_on_element=function(data, elem_name) {

Re: [R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
On Mon, Aug 8, 2011 at 6:08 PM, peter dalgaard wrote: > > On Aug 9, 2011, at 00:29 , Dennis Murphy wrote: > >> Hi: >> >> Here are a couple of ways; there may well be better ones. >> >> # (1)  Use the get() function: >> mean_on_element=function(data, elem_name) { >>   with(data, mean(get(elem_name)

Re: [R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
On Mon, Aug 8, 2011 at 6:08 PM, peter dalgaard wrote: > > On Aug 9, 2011, at 00:29 , Dennis Murphy wrote: > >> Hi: >> >> Here are a couple of ways; there may well be better ones. >> >> # (1)  Use the get() function: >> mean_on_element=function(data, elem_name) { >>   with(data, mean(get(elem_name)

Re: [R] enclosing with() in a function

2011-08-08 Thread peter dalgaard
On Aug 9, 2011, at 00:29 , Dennis Murphy wrote: > Hi: > > Here are a couple of ways; there may well be better ones. > > # (1) Use the get() function: > mean_on_element=function(data, elem_name) { > with(data, mean(get(elem_name))) > } > mean_on_element(data, 'x') I suspect this goes belly-u

Re: [R] enclosing with() in a function

2011-08-08 Thread Dennis Murphy
Hi: Here are a couple of ways; there may well be better ones. # (1) Use the get() function: mean_on_element=function(data, elem_name) { with(data, mean(get(elem_name))) } mean_on_element(data, 'x') # (2) Lose 'with' and use subscripting instead: mean_on_element=function(data, elem_name) {

Re: [R] enclosing with() in a function

2011-08-08 Thread R. Michael Weylandt
Hi Tom, What exactly is this function supposed to do? Your immediate problem is that you are passing it a string "x" and asking for a mean of the string "x" (hence complaints that it's not numeric) but I'm a little confused as to what this is supposed to do when it works. If you just want the mea

[R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
Hi All, I want to enclose with() in a function mean_on_element. Obviously, it is not working. The problem is how to specify the element name with a function body. Does anybody have any suggestion? Thanks! > data=list(x=1:10) > with(data, mean(x)) [1] 5.5 > > mean_on_element=function(data, elem_na