I'll explain my problem using an example with the iris table. Let's say I want to create a tree between sepal width and species. For this I will use this code:
ctree(Species~Sepal.Width,data=iris)->a
plot(a,type="simple")
The problem is that, if I want to do a data frame, for example counting the quantity of cases in each node (from 0 to 2.9; 2.9 to 3.3, etc), the only way I've found to do this is by creating a new vector manually and then using the dcast
or table
function.
The problem with this solution is that if I had a bigger tree result, it could be quite difficult. Do you know any other solution for this? Thanks a lot.
Actually, the party structure created by
ctree
has that information stored in it. Using your example,a[1]$fitted[,1]
has which leaf each point ended up in. So you can get the number of points at each leaf with:If you are trying to see the rules that go with the leaf numbers, you can use: