Re: [R] rename cols

From: Timothy Bates <timothy.c.bates_at_gmail.com>
Date: Mon 11 Sep 2006 - 17:11:41 GMT


> How do you rename column names? i.e. V1 --> Apple; V2 --> Orange, etc.

I'm fairly new myself, but...

People will tell you:
1. See if just asking for help on the verb you want works

    ?rename #out of luck, never mind

2. If not, try some variations

    ?name #too bad: turns out this doesn't help here     

3. If not, then search more widely

    RSiteSearch("rename") # sadly that's too vague to help

4. If not, then ask here, giving a clear and concise example of your needs, data, and expected result.

i.e.,I have

    A <- c(V1=2, V2=3)

How can I change the variable names?

But for really simple questions like this (which are more like the syntax of the language than anything more complex, you will not regret buying "An Introduction to R", and something like "Statistics an introduction using R", both on Amazon for quick delivery.

The answer is that the function to get names also sets them if it is passed an array of names, so:

A <- c(V1=2, V2=3)

names(A)

    [1] "V1" "V2"

names(A) <- c("Apple", "Orange")

A
 Apple Orange

     2 3



R-help@stat.math.ethz.ch 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. Received on Tue Sep 12 06:24:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 11 Sep 2006 - 21:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.