Skip to content
Prev 35144 / 398502 Next

variable name of variable in dataframe

Dear Tobias,

The trick is "Programming on the Language", see e.g. the "R Language Manual". 
Construct the expression you want, and have it explicitly parsed and evaluated.

toy <- function(b=.95){
  toyframe <- eval(parse(text=paste("data.frame(lion", b, " = c(1, 2))", sep="")))
  return(toyframe)
z}
toy()
toy(0)

HTH

Thomas


---

Thomas Hotz
Research Associate in Medical Statistics
University of Leicester
United Kingdom

Department of Epidemiology and Public Health
22-28 Princess Road West
Leicester
LE1 6TP
Tel +44 116 252-5410
Fax +44 116 252-5423

Division of Medicine for the Elderly
Department of Medicine
The Glenfield Hospital
Leicester
LE3 9QP
Tel +44 116 256-3643
Fax +44 116 232-2976