データフレームのリストでデータフレームを分割したいと思います。それを分割する理由は、常にfather
が続きmother
、次に が続くということoffspring
です。ただし、これらのファミリ メンバーには複数の行がある場合があります (これらは常に連続しています。たとえばfather
、番号 1 は行 1 と行 2 にあります)。以下の例では、2 つのファミリがあり、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)