If you run the following:
library(RWeka)
data(iris)
res = J48(Species ~., data = iris)
res
will be a list of class J48
inheriting from Weka_tree
. If you print it
R> res
J48 pruned tree
------------------
Petal.Width <= 0.6: setosa (50.0)
Petal.Width > 0.6
| Petal.Width <= 1.7
| | Petal.Length <= 4.9: versicolor (48.0/1.0)
| | Petal.Length > 4.9
| | | Petal.Width <= 1.5: virginica (3.0)
| | | Petal.Width > 1.5: versicolor (3.0/1.0)
| Petal.Width > 1.7: virginica (46.0/1.0)
Number of Leaves : 5
Size of the tree : 9
I would like to get the properties and their values by their order from right to left. So for this case:
Petal.Width, Petal.Width, Petal.Length, Petal.Length.
I tried to enter res to a factor and to run the command:
str_extract(paste0(x, collapse=""), perl("(?<=\\|)[A-Za-z]+(?=\\|)"))
with no success. Just to remember that we should ignore the left around characters.