r - extracting unique rows of data using dplyr -


this question has answer here:

i'm trying extract rows when b unique value per a.

here sample data

a <- c(1,1,2,2,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,9,9,9,10,10,10) b <- c(1,2,1,1,5,5,6,1,1,1,3,2,2,1,1,2,3,1,2,3,4,4,1,2,2) df1 <- data.frame(a, b) 

and using dplyr package

library(dplyr)  unique <- df1 %>%   group_by(a) %>%   filter(n_distinct(b)) 

the desired output should data frame length 18

we can try

library(dplyr) df1 %>%     distinct() 

or in base r

unique(df1) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -