I have a table with columns A and B and I want to list down all unique elements in column B related to each unique element in column A in R.
Asked
Active
Viewed 60 times
-2
-
1`aggregate(B~A, df, function(x) toString(unique(x)))` – Ronak Shah Aug 29 '19 at 07:49
-
Thanks for the prompt response. I ran it however, it has been almost 2 hrs now and my code hasn't finished executing. Is this normal given that I have some 2,50,00,000 rows? – Akshit Aug 29 '19 at 10:19
1 Answers
0
You probably want to use the function aggregate
Assuming the dataframe/datatable has the name df
, you can use the code below:
aggregate(B~A, df, function(x) toString(unique(x)))

txemsukr
- 1,017
- 1
- 10
- 32
-
Thanks for the prompt response. I ran it however, it has been almost 2 hrs now and my code hasn't finished executing. Is this normal given that I have some 2,50,00,000 rows? – Akshit Aug 29 '19 at 10:19
-
If you have 2 billion rows, it's not surprising that it takes a lot of time. – txemsukr Aug 30 '19 at 07:36