On 28/05/2012 08:27, Jeff Newmiller wrote:
It is isn't easy to write code that works with column names that have spaces. You could 
rewrite rpart, or just rename the columns in your data frame to work around the 
"bug". See ?names.

In any case, rpart pre-dates the `` notation that made this possible.

Note that this looks very like the iris data set, which does have syntactic names. Not that we have the reproducible code the posting guide asked for ....

From ?formula

     Variable names can be quoted by backticks ‘`like this`’ in
     formulae, although there is no guarantee that all code using
     formulae will accept such non-syntactic names.


---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnew...@dcn.davis.ca.us>         Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

Raji<raji.sanka...@gmail.com>  wrote:

Hi,

Our data has column names with spaces in that.The names in dataFrame
are,
    *[1] "Sepal Length" "Sepal Width"  "Petal Length" "Petal Width"
"Species" *
When i try to use the column names in rpart function, it gives the
following
error.
*   rp<-rpart(as.factor(`Species`)~`Sepal Length`)

You don't need `` unless the name is non-syntactic, e.g. contains a space.


Error in `[.data.frame`(frame, predictors) : undefined columns
selected*

But , a similar call works for kmeans/nnet functions.For example,
  *nn<-nnet(as.factor(`Species`)~`Sepal Length`,size=3)*

Is there any way in which column names with spaces be used in rpart
function
like being used in nnet/kmeans function?

Thanks in advance for your help,
Raji


--
Brian D. Ripley,                  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@r-project.org 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.

Reply via email to