I have a large dataframe (3M rows) with two columns: key
and value
, and I want to create a list of vectors (or any similar data structure), with as many elements as the number of different value
, such that element k of the list is the vector of key
whose value
is k.
# original dataframe:
df
# key value
# 4 a
# 2 a
# 3 k
# 12 a
# expected output:
list
# $`a`
# [1] 4 2 12
#
# $`k`
# [1] 3
I tried with a loop but it is very slow (it took 6 hours to treat 1M rows, and I stopped it there). Is there a more efficient method?