Hi Dennis,

Thanks for this suggestion (which I got to run!), as this code makes
intuitive sense, whereas not all the other suggestions were that
straightforward. I'm relatively new to programming in R and am very
appreciative that you and others take time to help out where you can.

Sincerely,
Sarah



On Sun, Jun 13, 2010 at 8:47 PM, Dennis Murphy [via R] <
ml-node+2253845-1393472685-291...@n4.nabble.com<ml-node%2b2253845-1393472685-291...@n4.nabble.com>
> wrote:

> Hi:
>
> Another possibility:
>
> as.data.frame(with(data[!duplicated(data), ], table(unit))
>   unit Freq
> 1  123    3
> 2  345    4
>
> HTH,
> Dennis
>
> On Sun, Jun 13, 2010 at 9:07 AM, Birdnerd <[hidden 
> email]<http://user/SendEmail.jtp?type=node&node=2253845&i=0>>
> wrote:
>
> >
> > I have a data frame with two factors (sampling 'unit', 'species'). I want
>
> > to
> > calculate the number of unique 'species' per 'unit.' I can calculate the
> > number of unique values for each variable separately, but can't get a
> count
> > for each ‘unit’.
> >
> > > data=read.csv("C:/Desktop/sr_sort_practice.csv")
> > > attach(data)
> >
> > > data[1:10,]
> >   unit species
> > 1   123    ACMA
> > 2   123    LIDE
> > 3   123    LIDE
> > 4   123    SESE
> > 5   123    SESE
> > 6   123    SESE
> > 7   345    HEAR
> > 8   345    LOHI
> > 9   345    QUAG
> > 10  345    TODI…..
> >
> > > sr.unique<- lapply (data, unique)
> > $unit
> > [1] 123 345 216
> > $species
> >  [1] ACMA  LIDE  SESE  HEAR  LOHI  QUAG  TODI  UMCA  ARSP  LIDE
> >
> > > sapply (sr.unique,length)
> >    unit species
> >      3      10
> >
> > Then, I get stuck here because this unique species count is not given for
>
> > each ‘unit’.
> > What I'd like to get is:
> >
> > unit species
> > 123    3
> > 345    4
> > 216    --
> >
> > Thanks--
> >
> > --
> > View this message in context:
> >
> http://r.789695.n4.nabble.com/Count-of-unique-factors-within-another-factor-tp2253545p2253545.html<http://r.789695.n4.nabble.com/Count-of-unique-factors-within-another-factor-tp2253545p2253545.html?by-user=t&by-user=t>
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [hidden email] 
> > <http://user/SendEmail.jtp?type=node&node=2253845&i=1>mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> [hidden email] <http://user/SendEmail.jtp?type=node&node=2253845&i=2>mailing 
> list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> ------------------------------
>  View message @
> http://r.789695.n4.nabble.com/Count-of-unique-factors-within-another-factor-tp2253545p2253845.html
> To unsubscribe from Count of unique factors within another factor, click
> here< (link removed) >.
>
>
>


-- 
Sarah E. Haas
haaszool...@gmail.com

Center for Applied Geographic Information Science (CAGIS)
Department of Geography and Earth Sciences
University of North Carolina at Charlotte
9201 University City Blvd.
Charlotte, NC 28223, USA
http://www.gis.uncc.edu/

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Count-of-unique-factors-within-another-factor-tp2253545p2254591.html
Sent from the R help mailing list archive at Nabble.com.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to