2017-08-15 43 views
0

我與特定格式的data.frame:合併行

df <- structure(list(Left.align = c("A", "B", "C", "F"), Right.align = c("B", 
"A", "D", "E"), Center.align = c(2, 2, 3, 6)), .Names = c("Left.align", 
"Right.align", "Center.align"), row.names = c(NA, -4L), class = "data.frame") 

df 
    Left.align Right.align Center.align 
1   A   B   2 
2   B   A   2 
3   C   D   3 
4   F   E   6 

我會以除去BA 2,因爲結果是一樣的是AB 2.如何我會在R這麼做嗎?

謝謝!

+1

只是做'DF1 [!複製(T(適用(DF1,1,排序))) ,]' – akrun

回答

1

我們可以sort通過行,然後用duplicated得到一個合理的索引子集數據集的行

df1[!duplicated(t(apply(df1, 1, sort))),] 
+0

如果我有一個在不同列中具有相同字符的表,例如:1 AA 2如何刪除這些行?謝謝 –

+0

@LeandroNascimentoLemos你想刪除那些列嗎? – akrun