My data is linked through an Id
, ParentId
system and I have managed to add correct integer levels
, however, I would like to compose a function that automatically nests my 5 tiered hierarchy as a pathString
for data.tree
.
Structure:
Id Name ParentId ParentName Level
701F0000006Iw8E 'Paid Media' NA NA 1
701F0000006IS1t 'Bing ABC' 701F0000006Iw8Y 'Bing' 3
701F0000006IS28 'Bing DEF' 701F0000006Iw8Y 'Bing' 3
701F0000006IS23 'Bing GHI' 701F0000006Iw8Y 'Bing' 3
701F0000006Imq9 'Bing JKL' 701F0000006Iw8Y 'Bing' 3
701F0000006IS1y 'Bing MNO' 701F0000006Iw8Y 'Bing' 3
701F0000006Iw8Y 'Bing' 701F0000006Iw8E 'Paid Media' 2
701F0000006IvcW 'Google' 701F0000006Iw8E 'Paid Media' 2
7012A000006rhY8 'Adwords ABC' 701F0000006IvcW 'Google' 3
701F0000006IS1j 'Adwords DEF' 701F0000006IvcW 'Google' 3
701F0000006IS1o 'Adwords GHI' 701F0000006IvcW 'Google' 3
701F0000006IS1Z 'Adwords JKL' 701F0000006IvcW 'Google' 3
701F0000006Ieci 'Adwords MNO' 701F0000006IvcW 'Google' 3
Currently, I run into the issue that pathString gets read only by a single tier in the following:
dat$pathString <- paste(dat$ParentId,
dat$Id,
sep = "/")
Ex.
"NA/701F0000000SOEq"
Which, in reality to populate the whole tree correctly, I would need to identify all subsequent parents within the string:
"NA/701F0000006Iw8E/701F0000006Iw8Y/701F0000006IS1t" for "Bing ABC"
Ideally, a single expression will work equivalently for all levels but I understand if each level needs to be handled separately.
Full Id,ParentId system here: Dropbox Link