[R] How to findout the name of a dataframe

David Winsemius dwinsemius at comcast.net
Sun Feb 17 19:32:45 CET 2013

On Feb 17, 2013, at 5:51 AM, Frans Marcelissen wrote:

> Let'say we have a dataframe mydata with column v1. If mydata$v1 is passed
> to a function, is there way, then, to extract the name of the dataframe?
> What I now do is passing the name of the dataframe to the funcion, so
> passing two parameters. Maybe with mydata$v1 it is not possible, but with
> mydata['v1'] or mydata[,'v1'] it is?

It will depend on the specifics. The usual way is with deparse(substitute(arg))

> d <- data.frame(a="a")

> gn <- function(col) print(deparse(substitute(col)))
> gn(d)
[1] "d"
> gn(d$a)
[1] "d$a"

You do realize that mydata$v1 is identical (after evaluation, anyway)  to  mydata[,'v1'] , but not to mydata['v1'], don't you?

> gn(d['a'])
[1] "d[\"a\"]"

> Thanks
> Frans
> -------------------
> Frans Marcelissen
> fransiepansiekevertje at gmail.com
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at 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.

David Winsemius
Alameda, CA, USA

More information about the R-help mailing list