I have a table that looks like this:
I am looking for a table that gives a frequency count of the elements in the fields l_0, l_1, l_2, l_3
.
For example the output should look like this:
| author_id | year | l_o.name | l_0.count| l1.name | l1.count | l2.name | l2.count| l3.name | l3.count|
| 2164089123 | 1987 | biology | 3 | botany | 3 | | | | |
| 2595831531 | 1987 | computer science | 2 | simulation | 2 | computer simulation | 2 | mathematical model | 2 |
Edit:
In some cases the array field might have more than one type of element. For example l_0
could be ['biology', 'biology', 'geometry', 'geometry']
. In that case the output for fields l_0, l_1, l_2, l_3
would be a nested repeated field with all the elements in l_0.name
and all the corresponding counts in the l_0.count
.