I'm incredibly unsure what to call this problem, I feel like there might be a compsci term for it but I'm not familiar with it.
As a trivial example, let's say I have a simple example of parent company and subcompanies identified by unique numbers. What I want, is if Company A owns Company B, and Company B owns Company C, I want my data to reflect that Company A owns Company C. Here's a trivial example
What I would like to do is transform this data:
Parent Sub
133 922
199 633
210 677
633 792
To This Data where it takes sub-sub company 792 and assigns it to company 199 as well.
Parent Sub
133 922
199 633
210 677
199 792
I feel like I could brute force this with VBA where it just does a search for every subcompany to see if it has a subcompany in turn repetitively, but I'm wondering if there's a smarter pre-built way of doing it already in excel somehow.
Also willing to transfer the data to R and try something there if if there's an easier solution in R.

