John,

I like using stringr or stringi for this type of thing. stringi is written in C 
and faster so I now typically use it. You can also use base functions. The main 
trick is the handy names() function.

> example <- data.frame("Col 1 A" = 1:3, "Col 1 B" = letters[1:3])
> example
  Col.1.A Col.1.B
1       1       a
2       2       b
3       3       c
> library(stringi)
> names(example) <- stri_replace_all_fixed(names(example), ".", "_")
> example
  Col_1_A Col_1_B
1       1       a
2       2       b
3       3       c

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Jun 8, 2015, at 9:15 AM, John Sorkin <jsor...@grecc.umaryland.edu> wrote:
> 
> I am reading a csv file. The column headers have spaces in them. The spaces 
> are replaced by a period. I want to replace the space by another character 
> (e.g. the underline) rather than the period. Can someone tell me how to 
> accomplish this?Thank you,
> John
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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