Skip to content
Prev 87014 / 398502 Next

elements that appear only once

Robin Hankin <r.hankin at noc.soton.ac.uk> writes:
You could go 

sort(unique(a))[table(a)==1]

(without the sort(), things go pearshaped, try setting

a <- factor(c(1,1,1,2,3,4,4,4,4,5),levels=5:1)

wnd you'll see).

If we assume that a is a factor, another option is

levels(a))[table(a)==1]

but that also has the problem of returning a character vector.