Tree structure with data.tree in R: NAs

256 Views Asked by At

I am trying to develop a tree structure in R using data.tree . I am really new in using tree structures. Specifically, I have been following the tutorial: https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html#trees-in-data.tree. However, when I am converting to node, the variables referring to each leaf appear to be NA. Specifically, my code is:

library(data.tree)
library(treemap)

library(vcd)
data(Arthritis)
head(Arthritis)
Arthritis$pathString <- paste("progress",
                              Arthritis$Treatment,
                              Arthritis$Improved,
                              Arthritis$ID,
                              sep= "/")

data_arth <- as.Node(Arthritis)
print(data_arth, "sex", limit = 10)

Which gives me:

enter image description here

While I would expect next to each ID to have the respective sex value. Any ideas what might be wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

There is a typo: The column name is Sex instead of sex:

print(data_arth, "Sex", limit = 10)
#                          levelName Sex
#1  progress                          NA
#2   ¦--Treated                       NA
#3   ¦   ¦--Some                      NA
#4   ¦   ¦   ¦--57                     2
#5   ¦   ¦   ¦--5                      2

colnames(Arthritis)
#[1] "ID"         "Treatment"  "Sex"        "Age"        # "Improved"   "pathString"