I have a dataframe like this:
> df
Person a b c d
John 1 0 1 1
James 0 1 1 0
Keith 1 0 0 0
Boris 0 1 0 0
...
And I need to transform it into a list of vectors with names of elements being corresponding to column names of dataframe and elements of the list being names of persons that have 1 in a column. For the above example the list should be like this:
> result_list
$a
[1] "John" "Keith"
$b
[1] "James" "Boris"
$c
[1] "John" "James"
$d
[1] "John"
Moving on to what I know, the vector of "switched" names for every column can be obtained like this:
df$Person[which(df$a == 1)]
But I'm not sure how to iterate over it properly, and I think there might be a tidy solution for the task that utilizes dplyr and purrr.