I want to strip the X's from the column names in this R data frame.
> d
days X2000 X2001 X2002 X2003
1 June-01 90 85 88 75
2 June-02 93 84 88 81
3 June-03 94 83 85 83
Here's what I've got so far. It gets me the column names that I want, by taking the substring of each of the columns 2 through 5.
> new_colnames <- c()
> for (name in colnames(d[2:5])) { new_colnames <- c(new_colnames, substring(name, 2)) }
> colnames(d) <- c('days', new_colnames)
> d
days 2000 2001 2002 2003
1 June-01 90 85 88 75
2 June-02 93 84 88 81
3 June-03 94 83 85 83
Is there a more efficient way of doing this? What is "best practice"?