[R] enclosing with() in a function

thmsfuller066 at gmail.com thmsfuller066 at gmail.com
Tue Aug 9 00:12:58 CEST 2011


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_name) {
+   with(data, mean(elem_name))
+ }
> mean_on_element(data, 'x')
[1] NA
Warning message:
In mean.default(elem_name) :
  argument is not numeric or logical: returning NA


-- 
Tom



More information about the R-help mailing list