我有一个看起来像这样的tbl_df:
Genes Cell AC FC
<chr> <chr> <dbl> <dbl>
1 abts-1 MSx1 94.9 6.81
2 acp-2 Ea 301. 32.4
3 acp-2 Ep 188. 20.6
4 acs-13 MSx1 69.1 8.20
5 acs-22 Ea 176. 19.4
6 acs-22 Ep 64.3 7.70
7 acs-3 Ea 156. 17.2
8 acs-3 Ep 75.5 8.87
9 add-2 Ea 123. 6.62
10 add-2 Ep 125. 6.69我想删除所有基于“基因”/不保留任何行的非唯一行。所以看起来应该是:
Genes Cell AC FC
<chr> <chr> <dbl> <dbl>
1 abts-1 MSx1 94.9 6.81
2 acs-13 MSx1 69.1 8.20其中没有重复的基因被选择,其余的列数据被保持。我试过了unique()、distinct()、!duplicated等等--这些都没有删除所有非unqiue行。
发布于 2021-01-15 14:50:36
试试这个:
library(dplyr)
#Code
new <- df %>%
group_by(Genes) %>%
filter(n()==1)输出:
# A tibble: 2 x 4
# Groups: Genes [2]
Genes Cell AC FC
<chr> <chr> <dbl> <dbl>
1 abts-1 MSx1 94.9 6.81
2 acs-13 MSx1 69.1 8.2 所使用的一些数据:
#Data
df <- structure(list(Genes = c("abts-1", "acp-2", "acp-2", "acs-13",
"acs-22", "acs-22", "acs-3", "acs-3", "add-2", "add-2"), Cell = c("MSx1",
"Ea", "Ep", "MSx1", "Ea", "Ep", "Ea", "Ep", "Ea", "Ep"), AC = c(94.9,
301, 188, 69.1, 176, 64.3, 156, 75.5, 123, 125), FC = c(6.81,
32.4, 20.6, 8.2, 19.4, 7.7, 17.2, 8.87, 6.62, 6.69)), row.names = c(NA,
-10L), class = "data.frame")https://stackoverflow.com/questions/65738170
复制相似问题