I have a data set with different levels and am trying to figure out a succinct way of pulling out the data from the lowest level for each entry. Here's some sample data with expected output. The blank cells are zeroes. This feels like it should be straightforward and I am running into problems. Any advice would be appreciated.
ID | Lvl 1 | Lvl 2 | Lvl 3 | Lvl 4 | Desired Output |
---|---|---|---|---|---|
1 | aaa | 0 | 0 | 0 | aaa |
2 | aaa | bbb | ccc | 0 | ccc |
3 | aaa | bbb | ccc | 0 | ccc |
4 | aaa | bbb | ccc | ddd | ddd |
I tried building a function with conditionals starting at the lowest level and working backward, but that seems like overkill.