【发布时间】:2016-10-31 16:15:09
【问题描述】:
我想在数据框列表中拆分数据框。拆分它的原因是我们将始终有father 后面跟着mother,而后面跟着offspring。但是,这些家庭成员可能有不止一行(它们总是在后面。例如,father 数字 1 在第 1 行和第 2 行)。在下面的示例中,我有两个家庭,然后我试图获取一个包含两个数据框的列表。
我的意见:
df <- 'Chr Start End Family
1 187546286 187552094 father
3 108028534 108032021 father
1 4864403 4878685 mother
1 18898657 18904908 mother
2 460238 461771 offspring
3 108028534 108032021 offspring
1 71481449 71532983 father
2 74507242 74511395 father
2 181864092 181864690 mother
1 71481449 71532983 offspring
2 181864092 181864690 offspring
3 160057791 160113642 offspring'
df <- read.table(text=df, header=T)
因此,我的预期输出 dfout[[1]] 将如下所示:
dfout <- 'Chr Start End Family
1 187546286 187552094 father
3 108028534 108032021 father
1 4864403 4878685 mother
1 18898657 18904908 mother
2 460238 461771 offspring
3 108028534 108032021 offspring'
dfout - read.table(text=dfout, header=TRUE)
【问题讨论】:
-
我不明白当您从一个家庭转到数据框各行的下一个家庭时,您有什么逻辑。
标签: r split subsequence