On 29/07/10 04:21, Jeremy Miles wrote:
I'd like a function that returns the variable name.

As in:

MyData$Var1

Would return:

Var1

Not quite sure what you mean, but does this get you started?

nn <- function(x) deparse(substitute(x))
str( z <- nn(airquality$Month) )
#  chr "airquality$Month"
## Not sure what now - maybe:
strsplit(z, "$", fixed = TRUE)[[1]][-1]
# [1] "Month"

You'll have to figure out with a variable called foo$bar$baz and with airquality["Month"] etc.

Hope this helps a little.

Allan

______________________________________________
R-help@r-project.org 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.

Reply via email to