Re: [R] elements that appear only once

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed 22 Feb 2006 - 20:24:33 EST

another approach is:

names(which(table(a) == 1))

but I don't know if you find this more elegant :)

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> 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
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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 Wed Feb 22 20:29:33 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:39 EST