I have a dataframe in which I need to count the number of occurences of values in a given list. Suppose I have a dataframe df:
df= DataFrame(:B1 => [1,1,2,2,3,4,5], :B2 => [1,7,7,2,2,5,5],:B3 => [2,2,2,3,3,3,3] )
7×3 DataFrame
Row │ B1 B2 B3
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 1 1 2
2 │ 1 7 2
3 │ 2 7 2
4 │ 2 2 3
5 │ 3 2 3
6 │ 4 5 3
7 │ 5 5 3
And I want to produce df2, where the column VAL has numbers 1 to 7 and I want to produce a count of them against the entries in columns of the dataframe df.
df2 = DataFrame(:VAL => collect(1:7),:B1 => [2,2,1,1,1,0,0], :B2 => [1,2,2,0,0,2,2],:B3 => [0,3,4,0,0,0,0])
7×4 DataFrame
Row │ VAL B1 B2 B3
│ Int64 Int64 Int64 Int64
─────┼────────────────────────────
1 │ 1 2 1 0
2 │ 2 2 2 3
3 │ 3 1 2 4
4 │ 4 1 0 0
5 │ 5 1 0 0
6 │ 6 0 2 0
7 │ 7 0 2 0
How can I do this?