[R] [FORGED] column name changes

Rolf Turner r.turner at auckland.ac.nz
Sun Jul 10 11:49:05 CEST 2016


On 10/07/16 17:34, Kristi Glover wrote:
> Hi R user,
> I wanted to change a column name with new one  but it comes with "." where there was space. Is there any way to keep my formate with space?
> Here what I found
>
>
> Images<-stack(imageA,imageB,imageC)
> names(Images)[3]<-c("dif of AB")
> head(Images)
> It gives the column name of 3 as a "dif.of.AB", but I wanted to be "dif of AB"
>
> I don't want to put the "." on the spaces.
>
>
> Any suggestions?


(1) Forget about what you "don't want" and leave the dots be. Spaces in 
variable/column names are an abomination, tolerated only by the great 
unwashed (i.e. users of Windoze).

(2) See fortune(37).

(3) It doesn't happen to me:

set.seed(42)
Images <- data.frame(x=rnorm(1),y=rnorm(10),z=rnorm(10))
names(Images)[3] <- "dif of AB"
names(Images)
> [1] "x"         "y"         "dif of AB"

There may be some setting that enforces "syntactically valid" names, but 
I see no such setting associated with names().  (There *is* such a 
setting associated with data.frame() --- are you telling the truth about 
how you formed the new names of "Images"?)

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list