as.character(quote(foo$Bar)[[3]])
[1] "Bar"
Hint: this is nothing to do with data frames ($ applies to lists). $ is an operator, so foo$Bar is a call. quote() stops it being evaluated, [[3]] selects the third of the elements (which are $, foo, Bar) and as.character turns the name into a character string.
On Mon, 3 May 2010, adrien Penac wrote:
Hello, I can't find how to get de column name from a data.frame dollar reference. To make it simple, I'd like to obtain "Bar" from a "foo$Bar" notation. I've tried col.names(foo$Bar), names(foo$Bar) and so on without sucess. Regards Blaise
-- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ 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.