I am trying to export the tree splitting results from a rpart object.  I
can visualize the splits by printing the rpart object (shown below for my
rpart object, model.prune).  However, this printed result is not a
dataframe and I am unable to export this information in .csv format.

I can view the frame details (model.prune$frame), but this object does not
contain the split information at each branch.  If possible, I'd just like
to append the branch splits to the model.prune$frame and then export the
dataframe.

Thanks in advance for any help.

Jared


> model.prune
n= 1922

node), split, n, deviance, yval
      * denotes terminal node

 1) root 1922 5452.32300 1.4621220
   2) bio_1_mn< 1214.297 970  758.84340 0.7968852 *
   3) bio_1_mn>=1214.297 952 3826.83500 2.1399370
     6) bio_5_mn>=3245.887 529 2049.01000 1.7504010
      12) bio_1_mn>=1973.455 104  141.46200 0.9568643 *
      13) bio_1_mn< 1973.455 425 1826.03300 1.9445840
        26) bio_4_mn>=63758.58 384 1020.37200 1.7541630 *
        27) bio_4_mn< 63758.58 41  661.32810 3.7280420
          54) m44_04_mn>=37.7683 28  124.25710 2.3292560 *
          55) m44_04_mn< 37.7683 13  364.28790 6.7408120 *
     7) bio_5_mn< 3245.887 423 1597.17100 2.6270880
      14) bio_2_mn< 1168.864 115  215.84920 1.5978740 *
      15) bio_2_mn>=1168.864 308 1214.02100 3.0113720
        30) bio_10_mn< 2395.813 90  218.46630 2.0642790 *
        31) bio_10_mn>=2395.813 218  881.49820 3.4023730
          62) elev_min< 14.5 30   71.33518 1.9906610 *
          63) elev_min>=14.5 188  740.83450 3.6276460 *

outfile <-paste(directory,"CaRegTree_Test.csv",sep="")
write.csv(model.prune,file=outfile, quote = FALSE, row.names = FALSE)

# which will result in:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
stringsAsFactors) :
  cannot coerce class '"rpart"' into a data.frame

        [[alternative HTML version deleted]]

______________________________________________
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