> -----Original Message----- > x<-dat.col > > Now, is there a function (or combination of functions) that > will let me assign the character string "dat.col" to a new > object (called y) without actually typing the characters > "dat$col", i.e. just by referring to x?
Yes. dat <- data.frame(col=sample(1:8)) namex <- function(x) deparse(substitute(x)) y <- namex(dat$col) y But wouldn't it be nicer to have the original name follow the data about so you only needed one object? The following mild extension of the above will do that,using attributes: namedvar <- function(x) { attr(x, "original.name") <- deparse(substitute(x)) x #returns the values as a vector with an attribute "original.name" } #Then y <- namedvar(dat$col) plot(y, xlab=attr(y, "original.name") ) ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} ______________________________________________ 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.