Ott*_*tto 0 combinations r unique duplicates
我正在使用 R 并且我想删除 data.frame 中的组合。独特的功能似乎无法完成这项工作。
a b c
1 1 4 A
2 2 3 B
3 1 5 C
4 4 1 A
5 5 1 C
6 3 2 B
7 3 2 E
Run Code Online (Sandbox Code Playgroud)
我想得到看起来像这样的东西,只保留 a 列和 b 列的一个组合(c 列是频率度量):
a b c
1 1 4 A
2 2 3 B
3 1 5 C
Run Code Online (Sandbox Code Playgroud)
非常感谢!
PS:问题的根源是返回此错误的 dcast 函数:聚合函数缺失:默认为长度(R reshape2 '聚合函数缺失:默认为长度')
df[!duplicated(t(apply(df[c("a", "b")], 1, sort))), ]
a b c
1 1 4 A
2 2 3 B
3 1 5 C
Run Code Online (Sandbox Code Playgroud)
在哪里:
df <- data.frame(
a = c(1L, 2L, 1L, 4L, 5L, 3L, 3L),
b = c(4L, 3L, 5L, 1L, 1L, 2L, 2L),
c = c("A", "B", "C", "A", "C", "B", "E")
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1573 次 |
| 最近记录: |