Thanks: Re: [R] count levels per factor level

Tord Snall tord.snall at ebc.uu.se
Fri Jan 10 16:19:03 CET 2003


Dear Lockwood,

As you can see, I'm a beginner...

But thank you very much! 

Sincerely,
Tord

Quoting "J.R. Lockwood" <lockwood at rand.org>:

> how about
> 
> buskartant$buskartant <- sapply( group.list, function(x)
> sum(!is.na(unique(x))) )
> 
> OR
> 
> buskartant$buskartant <- sapply( group.list, function(x)
> length(unique(x[!is.na(x)])) )
> 
> 
> On Fri, 10 Jan 2003, Tord Snall wrote:
> 
> > Date: Fri, 10 Jan 2003 15:19:18 +0100
> > From: Tord Snall <tord.snall at ebc.uu.se>
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] count levels per factor level
> > 
> > Dear all,
> > 
> > I would be really happy for help with the following because I will
> treat
> > many columns the same way.
> > 
> > nlevels per ObjektID is what I want, but nlevels returns all levels
> > occurring in cpy.busk$TradArt:
> > 
> > buskartant<- aggregate(list(trash = cpy.busk$TradArt), list(ObjektID
> =
> > cpy.busk$ObjektID), nlevels) 
> > 
> > But as you can see I use it below anyway. I could use any function
> instaed
> > of nlevels beacuse now I just want the ObjektID in the right order.
> > 
> > Greg Warnes kindly helped me with this solution: 
> > group.list <- split(cpy.busk$TradArt, cpy.busk$ObjektID)
> > buskartant$buskartant <- sapply( group.list, function(x)
> length(unique(x)) )
> > 
> > But the probelm is that unique considers NA as a category, and there
> is no
> > na.rm argument in unique().
> > 
> > Please give a hint.
> > 
> > Thanks a lot in advance!
> > 
> > Sincerely,
> > Tord
> > 
> >
> -----------------------------------------------------------------------
> > Tord Snäll
> > Avd. f växtekologi, Evolutionsbiologiskt centrum, Uppsala universitet
> > Dept. of Plant Ecology, Evolutionary Biology Centre, Uppsala
> University
> > Villavägen 14			
> > SE-752 36 Uppsala, Sweden
> > Tel: 018-471 28 82 (int +46 18 471 28 82) (work)
> > Tel: 018-25 71 33 (int +46 18 25 71 33) (home)
> > Fax: 018-55 34 19 (int +46 18 55 34 19) (work)
> > E-mail: Tord.Snall at ebc.uu.se
> > Check this: http://www.vaxtbio.uu.se/resfold/snall.htm!
> >
> ------------------------------------------------------------------------
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > 
> 
> J.R. Lockwood
> 412-683-2300 x4941
> lockwood at rand.org
> http://www.rand.org/methodology/stat/members/lockwood/
> 
>




More information about the R-help mailing list