[R] Dealing with data frame column names beginning with a numeric

Patrick Connolly p_connolly at ihug.co.nz
Mon Apr 16 22:22:37 CEST 2007

I wish to set up a simple function using boxplot so that it will be
available to someone using R for Windows.  (I myself use Linux.)

The way the data is organised makes it convenient to use the boxplot
function in a manner similar to this example given in the help.

>      mat <- cbind(Uni05 = (1:100)/21, Norm = rnorm(100),
+                   T5 = rt(100, df = 5), Gam2 = rgamma(100, shape = 2))
>      boxplot(data.frame(mat), main = "boxplot(data.frame(mat), main = ...)")

If one of those columns had a numeric beginning to its name, such as:

> colnames(mat)[3] <- "5T"

and then using boxplot the same way, it will prepend an "X" to the
column name "5T" in the changing to a dataframe.

I know I could use boxplot with a formula with the dataframe reshaped
which would get round the problem, but I wanted to introduce as few
new concepts as possible for someone new to using R.  So the question
is: Is there a way to get such a name without anything prepended into
boxplot when used this way?

I've been led to understand that some Windows' plotting devices lend
themselves to simpler editing than in Linux, so perhaps there is a
simple way to remove the "X" from the plot afterwards.  I know it
could be done with a postscript device by editing the file with a text
editor but that's not simple with Windows.


   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon

More information about the R-help mailing list