saulius88
asked on
Change data.tree node names in R
I would like to change the node names of my data.tree object (tjpCPI) from IDs to readable tags. A sample of the tree structure is here:
> print(tjpCPI, "CPI.Tag")
levelName CPI.Tag
1 378257447 CPI
2 ¦--378257497 Food
3 ¦ ¦--378259447 Cereals
4 ¦ ¦ ¦--378259457 Rice
5 ¦ ¦ ¦ ¦--378259467 Non Glutinous
6 ¦ ¦ ¦ ¦ ¦--378259477 Rice-A
7 ¦ ¦ ¦ ¦ °--378259487 Rice-B
8 ¦ ¦ ¦ °--378259497 Glutinous
9 ¦ ¦ ¦--378259507 Bread
10 ¦ ¦ ¦ ¦--378259517 White Bread
11 ¦ ¦ ¦ ¦--378259527 Bean Jam Buns
12 ¦ ¦ ¦ °--378259537 Curry Buns
13 ¦ ¦ ¦--378259547 Noodles
I would like levelName to become CPI.Tag.
How might I do that without needing to iterate through each node?
> print(tjpCPI, "CPI.Tag")
levelName CPI.Tag
1 378257447 CPI
2 ¦--378257497 Food
3 ¦ ¦--378259447 Cereals
4 ¦ ¦ ¦--378259457 Rice
5 ¦ ¦ ¦ ¦--378259467 Non Glutinous
6 ¦ ¦ ¦ ¦ ¦--378259477 Rice-A
7 ¦ ¦ ¦ ¦ °--378259487 Rice-B
8 ¦ ¦ ¦ °--378259497 Glutinous
9 ¦ ¦ ¦--378259507 Bread
10 ¦ ¦ ¦ ¦--378259517 White Bread
11 ¦ ¦ ¦ ¦--378259527 Bean Jam Buns
12 ¦ ¦ ¦ °--378259537 Curry Buns
13 ¦ ¦ ¦--378259547 Noodles
I would like levelName to become CPI.Tag.
How might I do that without needing to iterate through each node?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
I am here to help you with your open question. Do you still need help? I have the ability to alert more experts if you still need help.
If you solved the problem on your own, would you please post the solution here in case others have the same problem?
If you need me to delete this question just say "Delete."
Thank you for using Experts Exchange.
Regards,
Kyle Santos
Customer Relations