Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread John Sorkin
David,I appreciate you suggestion, but it won't work for me. I need to replace the space for a period at the time the data are read, not afterward. My variables names have periods I want to keep, if I use your suggestion I will replace the period inserted when the data are read, as well as the

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Mark Sharp
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

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread David L Carlson
You can use gsub() to change the names: dat - data.frame(Var 1=rnorm(5, 10), Var 2=rnorm(5, 15)) dat Var.1Var.2 1 9.627122 14.15376 2 10.741617 16.92937 3 8.492926 15.23767 4 12.226146 15.19834 5 8.829982 14.46957 names(dat) - gsub(\\., _, names(dat)) dat Var_1Var_2 1

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Sarah Goslee
Easiest? Use sub() to replace the periods after the fact. You can also use the check.names or the col.names arguments to read.table() to customize your import. Sarah On Mon, Jun 8, 2015 at 10:15 AM, John Sorkin jsor...@grecc.umaryland.edu wrote: I am reading a csv file. The column headers have

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread David L Carlson
Then using Sarah's suggestion something like? dat - read.table(text= + 'Var 1' Var.2 + 1 6 + 2 7 + 3 8 + 4 9 + 5 10, header=TRUE, col.names=c(Var_1, Var.2)) dat Var_1 Var.2 1 1 6 2 2 7 3 3 8 4 4 9 5 510 David C From: John Sorkin

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Sarah Goslee
I've taken the liberty of copying this back to the list, so that others can participate in or benefit from the discussion. On Mon, Jun 8, 2015 at 10:49 AM, John Sorkin jsor...@grecc.umaryland.edu wrote: Sarah, I am not sure how I use check.names to replace every space in the names of my

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Duncan Murdoch
On 08/06/2015 10:23 AM, Sarah Goslee wrote: Easiest? Use sub() to replace the periods after the fact. You can also use the check.names or the col.names arguments to read.table() to customize your import. Yes, check.names is the right idea. Use check.names = FALSE, then use sub() or gsub()

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread peter dalgaard
On 08 Jun 2015, at 17:03 , Sarah Goslee sarah.gos...@gmail.com wrote: I'd import them with check.names=FALSE, then modify them explicitly: mynames - c(x y, x y, x y, x y) mynames [1] x y x y x y x y mynames - sub( , ., mynames) mynames [1] x.y x.y x.y x.y mynames - paste(mynames,

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread John Sorkin
Sarah, Many, many thanks. 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)

Re: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread William Dunlap
mynames [1] x.y x.y x.y x.y mynames - paste(mynames, seq_along(mynames), sep=_) In addition, if there were a variety of names in mynames and you wanted to number each unique name separately you could use ave(): origNames - c(X, Y, Y, X, Z, X) ave(origNames, origNames,