Skip to content
Prev 262667 / 398502 Next

Renaming variables

Hi:

names() typically has to do with the names associated with
*components* of a data frame or list, which appears to be what you
have, reading between the lines. Here's a toy example:
a
1  1.291952883
2 -0.136706733
3  0.219528682
4 -0.174832617
5 -0.003101679
## b is a variable name within the data frame mydf, not the global environment:
Error: object 'b' not found
[1]  1.291952883 -0.136706733  0.219528682 -0.174832617 -0.003101679
b
1  1.291952883
2 -0.136706733
3  0.219528682
...

# OTOH,
b
1  1.291952883
2 -0.136706733
3  0.219528682
...

so by assigning mydf to an object named b, you can change the name of
mydf. Note, however, that mydf still exists; b is a copy of mydf.
rm(mydf) would remove the original in favor of the newly named copy.


HTH,
Dennis
On Tue, Jun 14, 2011 at 4:04 AM, mosojn <marta.osojnik at gmail.com> wrote: