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, seq_along(mynames), sep="_")
>> mynames
> [1] "x.y_1" "x.y_2" "x.y_3" "x.y_4"

Didn't he want x_y.1, not x.y_1? Obviously, just switch "." and "_" for that.

A potential improvement (in case not all columns are "x y") is to replace the 
last bit with make.unique(mynames).

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
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