Skip to content

Better way to change the name of a column in a dataframe?

5 messages · Ben Fairbank, Mike Prager, Andrew Robinson +2 more

#
"Ben Fairbank" <BEN at SSANET.COM> wrote:

            
This is slightly simpler than what you had:

      names(frame)[which(names(frame) == "cmlo3")] <- "col3"

There are probably better ways still.
#
Hi,

names(frame)[names(frame) == "cmlo3"] <- "col3"

should also work

Cheers

Andrew
On Thu, Dec 14, 2006 at 05:05:20PM -0500, Mike Prager wrote:

  
    
#
Ben Fairbank wrote:
well I would simply use

names(frame)[3] = 'col3'

(supposing you know the column number of your offending column anyway).
#
And there is the rename.vars() function in the gdata package.
-Don
At 11:39 AM -0600 12/14/06, Ben Fairbank wrote: