0

Say I'm using R and have a data table:

x <- data.table(V1 = c("A","A","A","B","B","C","D"))    
table(x)

gives the following:

A B C D     
3 2 1 1 

How do I extract the items which occur over n times? For example, the output should be "A" if n = 2, and "A" and "B" if n = 1, and "A", "B", "C" if n = 0.

wwl
  • 2,025
  • 2
  • 30
  • 51

1 Answers1

0

Use names(x)[x > n], where n is the desired number of times. For example, names(x)[x > 1] gives "A" "B"

wwl
  • 2,025
  • 2
  • 30
  • 51