3

I am creating some decision trees using the package rpart in R. I have discrete variables like age, no.of.children in my dataset. But the resulting decision tree has these variables n decimals. Which means, it is considered as continuous variables.

How to avoid this and how can i get these variables as discrete in my decision tree?

Manoj G
  • 1,776
  • 2
  • 24
  • 29

1 Answers1

2

Make them into factors, the standard way to represent discrete variables in R.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • If i do that way, the text in the decision tree plot is not showing exact numbers, instead showing some text characters which i couldn't interpret..... – Manoj G Mar 11 '13 at 06:43
  • 1
    As how to fix that, http://stackoverflow.com/a/3840211/987185 may suggest some ways. TL;DR: `text(tree, pretty=1)` should put actual labels on the plot of the tree. – musically_ut Mar 11 '13 at 15:27
  • @ManojG: You should post data and code if you are having specific problems. You can substitute random values for the data entries but make sure the structure of that dataset is the same. Check that with the `str` function. – IRTFM Mar 11 '13 at 17:23