I am having trouble building a tree.map from parent/child grouped pairs. Here's my sample data:

SubjectID <- c('101','101','101','102','103','103','103')
parent <- c(1387, 1620, 1743,986,1623,1191,1450)
child<-c(1620,1743,1859 ,1015,1385,1450,1623)
df<-data.frame(SubjectID, parent,child)

I've tried building the tree with tree.map:

df$pathString<- paste("study",df$SubjectID, df$parent, df$child, sep="/") as.Node(df)

The result is:

1  study           
2   ¦--101         
3   ¦   ¦--1387    
4   ¦   ¦   °--1620
5   ¦   ¦--1620    
6   ¦   ¦   °--1743
7   ¦   °--1743    
8   ¦       °--1859
9   ¦--102         
10  ¦   °--986     
11  ¦       °--1015
12  °--103         
13      ¦--1623    
14      ¦   °--1385
15      ¦--1191    
16      ¦   °--1450
17      °--1450    
18          °--1623

I would like the result to link the parent with child like this:

1  study           
2   ¦--101         
3   ¦   ¦--1387    
4   ¦   ¦   °--1620
5   ¦   ¦      °--1743
6   ¦   ¦         °--1859
9   ¦--102         
7   ¦   °--986     
8   ¦       °--1015
9   °--103         
10      ¦--1623    
11      ¦   °--1385
12      ¦--1191    
13      ¦   °--1450
14      ¦      °--1623

1 Answers

0
Sam S On

The blow codes work and gives exactly the same output.

library(data.tree)

SubjectID <- c('101','102','103','103')
parent <- c(1387, 986,1623,1191)
child1 <-c(1620,1015,1385,1450)
child2 <- c(1743,'','',1623)
child3 <- c(1859,'','','')
df<-data.frame(SubjectID, parent,child1,child2,child3)

df$pathString<- paste("study",df$SubjectID, df$parent, df$child1,df$child2,df$child3, sep="/") 

as.Node(df)

enter image description here