删除每个观察中的重复项

时间:2013-06-14 10:18:54

标签: r

我有类似testDF <- data.frame(v1 = c( 1, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 7, 7 ,9),v2 = c("a","b","c","d","d","e","e","e","d","d","a","a","a","b") )

的内容

我需要为v1上的每个障碍物摆脱v2中的重复...  得到类似

的东西

testDF <- data.frame(v1 = c( 1, 2, 3, 4, 4, 5, 5, 5, 7, 9), v2 = c("a","b","c","d","e","e","d","a","a","b") )

我怎么能这样做?谢谢!

1 个答案:

答案 0 :(得分:4)

只需使用unique(testDF)而不是获得以下输出

   v1 v2
1   1  a
2   2  b
3   3  c
4   4  d
6   4  e
8   5  e
9   5  d
11  5  a
12  7  a
14  9  b