Re: [R] elements that appear only once

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 22 Feb 2006 - 23:57:05 EST

I am not sure whether this is desirable but here is another way just in case:

   paste(setdiff(a, a[duplicated(a)]))

You could replace paste with as.character if you prefer or could remove it entirely if you want the result as a factor.

On 2/22/06, Robin Hankin <r.hankin@noc.soton.ac.uk> wrote:
> Hi.
>
> I have a factor and I want to extract just those elements that appear
> exactly once.
> How to do this?
>
> Toy example follows.
>
> > a <- as.factor(c(rep("oak",5) ,rep("ash",1),rep("elm",1),rep
> ("beech",4)))
> > a
> [1] oak oak oak oak oak ash elm beech beech beech beech
> Levels: ash beech elm oak
> > table(a)
> a
> ash beech elm oak
> 1 4 1 5
> >
>
> So I would want "ash" and "elm", because there is only one ash and
> only one elm in my wood.
>
> My Best Effort:
>
>
> > names(table(a)[table(a)==1])
> [1] "ash" "elm"
> >
>
> This doesn't seem particularly elegant to me; there must be a better
> way!
>
> anyone?
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
> tel 023-8059-7743
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 23 00:39:47 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 06:23:11 EST