0

Is there better way to compute this instead of:

length(unique(vector))

let's assume that we donno what class is the vector.

wBacz
  • 99
  • 9
  • @Cath, they are not asking to do this by group as far as I can see – talat Mar 28 '17 at 09:28
  • 1
    @docendodiscimus indeed but you can consider you have only one group and considering the target Q and the answers, I found it close enough (but looking for Q&A to add to the target) – Cath Mar 28 '17 at 09:30

1 Answers1

0

You can use

library(data.table)
vector <- c(1,2,2,2,3)
uniqueN(vector)
67342343
  • 806
  • 5
  • 11