[R] choosing a particular object

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Fri Mar 31 11:59:39 CEST 2006


Try

 test.fn <- function(obj.name, var.name="q2"){

  stopifnot( is.character(obj.name) & is.character(var.name) )
  x <- subset( get(obj), select=var.name )
  table(x)
 }



On Fri, 2006-03-31 at 12:44 +0300, Adrian DUSA wrote:
> Hello all,
> 
> I'd like to create a function which would do some analysis on a particular 
> object, which should be specified in advance. Something like:
> 
> > ls()
> [1] "aa" "bb" "cc"
> 
> Object <- "bb"
> var.name <- "q2"
> testfunction <- function(obj.name, var.name) {
>   temp <- give.me.the.object.called(Object)
>   table(temp[, var.name])
> }
> 
> This should perfom the same thing as:
> table(bb$q2)
> 
> Is this possible?
> TIA,
> Adrian
>




More information about the R-help mailing list