Hi everyone, and thanks for your replies.

Let me make this a little simpler. Please forget the plotting, that's not
the issue.

I have run the following line of code:

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?

Many thanks,

Mark Na




On Thu, Jan 17, 2013 at 3:20 PM, Bert Gunter <gunter.ber...@gene.com> wrote:

> ?
> But Pat...
>
> The canonical way to do this is:
>
> myPlotFin(Col2 ~ Col1, data = dat)
>
> I have no idea what the OP wants, but my guess is that the right
> answer is: Don't do that.
>
> Cheers,
> Bert
>
> On Thu, Jan 17, 2013 at 12:25 PM, Patrick Burns
> <pbu...@pburns.seanet.com> wrote:
> > If you want the column names but not
> > the data frame name, then you could do:
> >
> > with(dat, myPlotFun(Col1, Col2))
> >
> > Pat
> >
> > On 17/01/2013 20:07, Patrick Burns wrote:
> >>
> >> You are thinking that 'names' does something different
> >> than it does.  What you seem to be after is the
> >> deparse-substitute idiom:
> >>
> >> dat <- data.frame(Col1=1:10, Col2=rnorm(10))
> >> myPlotFun <- function(x, y) {
> >>     plot(y ~ x, xlab=deparse(substitute(x)),
> ylab=deparse(substitute(y)))
> >> }
> >> myPlotFun(dat$Col1, dat$Col2)
> >>
> >>
> >> Pat
> >>
> >> On 17/01/2013 18:53, mtb...@gmail.com wrote:
> >>>
> >>> Hello R-helpers,
> >>>
> >>> I have run the following line of code:
> >>>
> >>> x<-dat$col
> >>>
> >>> and now I would like to assign names(x) to be "dat$col" (e.g., a
> >>> character
> >>> string equal to the column name that I assigned to x).
> >>>
> >>> What I am trying to do is to assign columns in my dataframe to new
> >>> objects
> >>> called x and y. Then I will use x and y within a new function to make
> >>> plots
> >>> with informative axis labels (e.g., "dat$col" instead of "x". So, for
> >>> example, I would like to plot (y~x,xlab=names(x)) and have "dat$col"
> >>> printed in the x-axis label. I can do this all manually, by typing
> >>>
> >>> names(x)<- "dat$col)
> >>>
> >>> but I'd like to do it with non-specific code within my function so I
> >>> don't
> >>> have to type the variable names manually each time.
> >>>
> >>> Many thanks,
> >>>
> >>> Mark Na
> >>>
> >>>     [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> 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.
> >>>
> >>
> >
> > --
> > Patrick Burns
> > pbu...@pburns.seanet.com
> > twitter: @portfolioprobe
> > http://www.portfolioprobe.com/blog
> > http://www.burns-stat.com
> > (home of 'Some hints for the R beginner'
> > and 'The R Inferno')
> >
> > ______________________________________________
> > 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
>
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>

        [[alternative HTML version deleted]]

______________________________________________
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