如何基于R中的一个col在多个df中拆分数据帧

时间:2018-07-17 09:48:56

标签: r dataframe split

我有这样的df:

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
   ....

,我希望每个chrm独立拥有一个df。

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

我到目前为止所做的是:

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", ]
.....

但是我很确定有一种更快的方法来完成此操作,因此,如果有人可以给我任何优化建议,我将不胜感激!  谢谢!

0 个答案:

没有答案