-2

I have a data frame as below :

A  B
1  3
2  5
3  3
4  5
5  3

What I want to do is group the elements of A by B, as below:

B  A's
3  1,3,5
5  2,4
zx8754
  • 46,390
  • 10
  • 104
  • 180
  • Alternatively, if you want the elements to be individually accessible and the grouping is just pretty printing, `library(data.table); setDT(dt)[, .(As = .(A)), B]` – Akhil Nair Jul 13 '16 at 11:24

1 Answers1

0

We can try

library(data.table)
setDT(df1)[,.(As=toString(A)) , B]
akrun
  • 789,025
  • 32
  • 460
  • 575
  • 1
    One comment, you know it is a dupe, you still answer, I marked as dupe 2 minutes before you posted an answer... was it so hard to check if it is/was marked before posting, even if we assume "you don't know it is a dupe". This is low. – zx8754 Jul 13 '16 at 11:27