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

Gabor Grothendieck ggrothendieck at gmail.com
Mon Apr 16 22:29:48 CEST 2007


Try this:

boxplot(data.frame(mat), names = colnames(mat))

On 4/16/07, Patrick Connolly <p_connolly at ihug.co.nz> wrote:
> 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.
>
> Ideas?
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>   ___    Patrick Connolly
>  {~._.~}                         Great minds discuss ideas
>  _( Y )_                        Middle minds discuss events
> (:_~*~_:)                        Small minds discuss people
>  (_)-(_)                                   ..... Anon
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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