0

I have this data.frame:

df = data.frame(chr=c("chr1","chr1","chr1"),start=c(1,2,3),end=c(11,12,13),strand=c("+","+","-"),tid=c("t1","t1","t2"),exon_id=c(1,2,1))

I'm looking for a function that would convert df to a list of data.frames where the aggregating value is df$tid.

Without a function, for this toy example, it would be:

df.list = list(df[1:2,], df[3,])

Since df$tid[1:2] is t1.

user1701545
  • 5,706
  • 14
  • 49
  • 80

1 Answers1

2

You are looking for split:

split(df, df$tid)

should do the trick.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103