[R] Use a text variable's value to specify another varaible?

Erik Iverson iverson at biostat.wisc.edu
Fri Jan 26 17:19:21 CET 2007


Can I ask why you aren't just passing in the object to your function, 
but instead a text name for that object?

Ben Fairbank wrote:
> Greetings guRus --
> 
>  
> 
> If a variable, e.g., 'varname', is a character string, e.g. varname <-
> "datavector", and I want to apply a function, such as table(), to
> datavector, what syntax or method will do so using only the variable
> varname?  This seems similar to indirect addressing, but I have not seen
> a method for it in the R manuals.  Is there a general name for such
> indirect reference that one might search for?
> 
>  
> 
> (This came up while writing a function that takes the value of 'varname'
> from the keyboard and then applies functions to it.)
> 
>  
> 
> With thanks for any solution,
> 
>  
> 
> Ben Fairbank
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list