Assuming you attribute the name "dataset" to your data. A way to name a column using colnames and which.

Code to change V1 column name:
colnames(dataset)[which(colnames(dataset) == "V1")] <- "Toto"

You are asking to R in the column's names of dataset which one is "V1" (TRUE) and attributing to this column the new name "Toto".

You can also use the the number of column but even if it seems simpler it is not recommended as you can get problem if the column order is changed.

Code to change 1st column name:
colnames(dataset)[1] <- "Toto"

Xochitl C.

<>< <>< <>< <><

Xochitl CORMON
+33 (0)3 21 99 56 84

Doctorante en sciences halieutiques
PhD student in fishery sciences

<>< <>< <>< <><

IFREMER
Centre Manche Mer du Nord
150 quai Gambetta
62200 Boulogne-sur-Mer

<>< <>< <>< <><



Le 27/08/2013 02:20, Jeff Newmiller a écrit :
Your question prompts more questions than answers. Not sure what "imported from 
notepad" means (clipboard? delimited how?). Don't know what you obtained in R (what 
does the str function tell you? What about dput(head(yourdata)))? You really need to tell 
us what R code you executed  and data you gave it for us to understand what happened.

Please read the Posting Guide mentioned at the bottom of this message. You 
would probably also benefit from reading about how to make a reproducible 
example to illustrate your question. 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnew...@dcn.davis.ca.us>         Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

Docbanks84<mban...@partners.org>  wrote:
Hi ,

I just imported a large data set from notepad. I want to label the
columns
in R.

I used 'import Dataset' to bring in my data set
Now, I would like to label V1,V2,V3 etc??

Thanks



--
View this message in context:
http://r.789695.n4.nabble.com/Naming-columns-tp4674595.html
Sent from the R help mailing list archive at Nabble.com.

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