Remove duplicated sku per id

Hello,

How can I remove the SKU duplicated by RUT?

D <- data.frame(One = 1:30,
ID = c(1,1,1,1,1,1,1,1,1,
2,2,2,2,2,
3,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4),
SKU = c("A1","A2", "A3", "A4", "A5", "A6","A7", "A8", "A9",
"A1", "A2", "A3", "A3", "A3",
"A1","A2", "A3", "A3", "A3", "A3","A3", "A3", "A3",
"A1","A2", "A3", "A4", "A5", "A6","A7"))

in ID 2, remove two SKU A3
in ID 3, remove six SKU A3

NOTE: I tried with this: D[!duplicated(D, keyby = SKU[c("ID",)]),]
But still apprears SKU duplicated by ID, maybe because the real dataset has 10 columns?

NOTE: I tried: D[!duplicated(D$SKU, keyby = SKU[c("ID",)]),]
but it shows just ID 1.

Some options ?
Thanks a lot.

Try

library(tidyverse)
DD <- D |> distinct(ID, SKU, .keep_all = TRUE)
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.