-2

I am trying to run a loop to change the names of two columns in my data but the name of these two columns start with a number. For the same work I changed them (they were not starting with a number) by writing as shown below but it is not working.

Here is the code (the loop finishes later) :

 #Filtering

for(i in 1:length(names$ID)){
  f<-names$ID[[i]]
  corrpoints<-sprintf("corrpoints%i",as.numeric(levels(f))[f])
  pts=readOGR(dsn="C:/Users/Charlie/Desktop/Stage_permafrost/SIG/Quantification_des_mouvements/Corr_points_disp/Corr_points_ubaye", layer=corrpoints)
  pts$Gvalue2004<-pts$2004_red_gr
  pts$Gvalue2012<-pts$2012_red_gr
  pts$Aspect_mnt<-pts$Aspect_25m_

Any idea on how I could fix this?

Thanks

Bennett Brown
  • 5,234
  • 1
  • 27
  • 35
C.Serrano
  • 1
  • 4

1 Answers1

0

Your example is not reproducible for us. Column names CAN start with numbers. Use ticks around the name to access it as below. Whether this is a good idea is an entirely different story.

x <- mtcars
colnames(x)[1] <- '1mpg'
x$`1mpg`
JanLauGe
  • 2,297
  • 2
  • 16
  • 40