Re: [R] Naming an object after another object...can it be done?

2013-01-18 Thread S Ellison
 

 -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.


[R] Naming an object after another object...can it be done?

2013-01-17 Thread mtb954
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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread Wensui Liu
are you looking for assign()?
On Jan 17, 2013 1:56 PM, 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.


[[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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread mtb954
Hi Liu - I have been trying with assign() but it's not working. I don't
think that's what I'm looking forany other ideas? Many thanks, Mark

On Thu, Jan 17, 2013 at 1:11 PM, Wensui Liu liuwen...@gmail.com wrote:

 are you looking for assign()?
 On Jan 17, 2013 1:56 PM, 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.



[[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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread Patrick Burns

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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread Patrick Burns

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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread Bert Gunter
?
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

__
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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread mtb954
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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread Bert Gunter
On Thu, Jan 17, 2013 at 1:29 PM,  mtb...@gmail.com wrote:
 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?

No.  x contains only the values. As I said, don't do this.

-- Bert


 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





-- 

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

__
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.


Re: [R] Naming an object after another object...can it be done?

2013-01-17 Thread David Winsemius

On Jan 17, 2013, at 1:29 PM, mtb...@gmail.com wrote:

 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?

It is unclear what you intend. It is possible to rename the x-object and it 
is possible to name individual elements of a multi-element object named x. It 
is furthermore possble to construct an attribute that will remain with x. So, 
provide a complete example and it may become clearer. 

Also specify whether you are attempting to do this on an object which has been 
attached, and if so, then the right answer will be don't use attach().

-- 
David.
 
 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.

David Winsemius
Alameda, CA, USA

__
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.