0

I have a dataset with three variables: id (the id of a company), parent_id (the id of that company's parent company) and year. I have another dataset with just the parent companies (which are the companies that have id = parent_id). I need to add to this second dataset the companies from the first dataset by order. By order I mean they have different levels (level 1 have parent_id = id from the parent company; level 2 companies have parent_id = id from companies in level 1, and so on). So, I need to add all these companies by levels and by year.

I have no idea of how to do it.

  • 1
    Welcome to StackOverlfow. We can easily help you if you provide as an excerpt of your data, for example using `dput(your_data_frame)` and paste the result in your post. – TimTeaFan Jan 22 '23 at 09:41
  • Hey, have a look at this chapter in [R for Data Science](https://r4ds.had.co.nz/relational-data.html). This might help you – uke Jan 22 '23 at 10:01
  • @TimTeaFan I tried to apply your `across2` here but it did not work. Why? – TarJae Jan 22 '23 at 10:08
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a table or screenshot for example). One way of doing is by using the `dput` function on the data or a subset of the data you are using, then pasting the output into your question. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Jan 22 '23 at 10:52
  • Welcome to SO, JesusGarcia! Some other links for how to format your question to be _reproducible_: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. It might be as simple as [edit]ing your question and adding: `dput(head(x,10))` (or a reasonable number of rows) for each sample frame, and perhaps the same `dput` method for your expected output. Thanks! – r2evans Jan 22 '23 at 18:46

0 Answers0