I have the following data frame:
df <- structure(list(GENE= c("ENS1", "ENS2",
"ENS3", "ENS4", "ENS1", "ENS2", "ENS3"), group= c(1L,
1L, 1L, 2L, 3L, 3L, 3L)),
class = "data.frame", row.names = c(NA, -7L))
GENE group
ENS1 1
ENS2 1
ENS3 1
ENS4 2
ENS1 3
ENS2 3
ENS3 3
Since groups 1 and 3 are identical I would like to remove one of them. How can I do that?
Thank you
A base R option using stack
+ unstack
+ duplicated
setNames(
type.convert(
stack((u <- unstack(df))[!duplicated(u)]),
as.is = TRUE
), names(df)
)
which gives
GENE group
1 ENS1 1
2 ENS2 1
3 ENS3 1
4 ENS4 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With