group=c(1,1,2,2,3,4,4,5,5,6)
I am wishing to generate an output that looks like:
dup:4
nodup: 2
Basically I want to count how many values are duplicated 'dup' and count how many are not 'nodup'
group=c(1,1,2,2,3,4,4,5,5,6)
I am wishing to generate an output that looks like:
dup:4
nodup: 2
Basically I want to count how many values are duplicated 'dup' and count how many are not 'nodup'
Here is an option, get the frequency count of values with table, convert to logical > 1 and then do a table again
table(table(group) > 1)
If we need the label names as 'dup', 'nodup'
table(c('nodup', 'dup')[1 + (table(group) > 1)])
# dup nodup
# 4 2
Another base R solution using duplicated + unique
dup <- sum(duplicated(group))
nodup <- length(unique(group))-dup
such that
> dup
[1] 4
> nodup
[1] 2