[R] column name changes

Jim Lemon drjimlemon at gmail.com
Sun Jul 10 12:18:09 CEST 2016


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"
> x
 a b dif of AB
1 1 2         3
2 2 3         4
3 3 4         5
> x$dif of AB
Error: 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.



More information about the R-help mailing list