taking the following data
A <- c(4,4,4,5,5,5,5,6,6)
B <- c(1,2,3,1,3,4,3,2,7)
data1 <- data.frame(A,B)
I want to remove the duplicated B values for each A.
So my new table should remove data1[7,]
I want to use the dplyr() package
And have tried the following code
data2 <- data1 %>%
group_by(A) %>%
filter(slice(B(1)))
Can someone help me with the correct filter() command
You can try
library(dplyr)
data1 %>%
group_by(A) %>%
filter(!duplicated(B))#or
#slice(which(!duplicated(B)))
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