-1

I have the following data frame:

df<-data.frame(store=c("A","A","A","A","B","C","C","C","C","C"),
               quantity=c(12,2,5,10,2,12,4,5,6,8))

df

    store quantity
1      A       12
2      A        2
3      A        5
4      A       10
5      B        2
6      C       12
7      C        4
8      C        5
9      C        6
10     C        8

I want to drop the rows where store category is <2 i.e. from the above table, i want to drop row no 5 as store B occurs only once?

Nishant
  • 1,063
  • 13
  • 40

1 Answers1

1

A base R solution would be

df[!(df$store %in% names(which(table(df$store) < 2))),]
#>    store quantity
#> 1      A       12
#> 2      A        2
#> 3      A        5
#> 4      A       10
#> 6      C       12
#> 7      C        4
#> 8      C        5
#> 9      C        6
#> 10     C        8
Allan Cameron
  • 147,086
  • 7
  • 49
  • 87