0

I hava a df like this:

chr pos reptime diff
chr1    35000   0.299974    0
chr1    45000   0.300823    0.000849
chr1    55000   0.30181 0.000987
chr2    65000   0.302636    0.000826
chr2    75000   0.303478    0.000842
   ....

and I would like to have one df independently for each chrm.

df_chr1

chr pos reptime diff
chr1    35000   0.299974    0
chr1    45000   0.300823    0.000849



df_chr2
chr pos reptime diff
chr2    65000   0.302636    0.000826
chr2    75000   0.303478    0.000842

what I did so far is:

tsv <- read_delim("outprefix_window.reptime.tsv", 
                       "\t", escape_double = FALSE, col_names = TRUE, 
                       trim_ws = TRUE)

chr1 <- tsv[tsv$chr == "chr1", ]
chr2 <- tsv[tsv$chr == "chr2", ]
chr3 <- [tsv$chr == "chr3", ]
.....

But I am pretty sure that there is a faster way to do it, so please, if someone can give me any advice to optimize it, I will appreciate! Thanks!

Mia Lua
  • 157
  • 1
  • 11
  • 2
    `split(df, df$chr)` – Sotos Jul 17 '18 at 09:49
  • IN that case I get a list nd I have to process it to get independent df. What I am asking is if there is a fast way to split a data frame in multiple and independent df. – Mia Lua Jul 17 '18 at 10:31

0 Answers0