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? Thanks
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
Hi Kristi, The period is there for a reason. If you want to extract that column like this: x<-data.frame(a=1:3,b=2:4,c=3:5)> names(x)[3]<-"dif of AB" > xa b dif of AB 1 1 2 3 2 2 3 4 3 3 4 5> x$dif of ABError: unexpected symbol in "x$dif of"> x$'dif of AB'[1] 3 4 5 you will have to quote the column name every time. Jim On Sun, Jul 10, 2016 at 3:34 PM, Kristi Glover <kristi.glover at hotmail.com> 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? > > Thanks > > ______________________________________________ > R-help at 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.