One way is to exclude the NAs from consideration by creating a new object without NAs in that column:
newTrees <- Trees[!is.na(Trees$SppID),] tapply(newTrees$SppID, newTrees$PlotID, function(x) length(unique(x))) On Wed, Jul 29, 2009 at 2:13 PM, Ian Chidister<ian.chidis...@gmail.com> wrote: > Hi All- > > Thanks for your quick responses. I was looking for unique instances, so > Jim's and Daniel's suggestions got the job done. Using "length" alone > didn't discriminate between multiple occurrences of the same species and > multiple species. > > I do have one followup question- my full data set (not the example data) has > a number of NAs in the SppID column, and [r] is currently counting the NAs > as species occurrences. Using Jim's code, I tried: > >>tapply(SppID, PlotID, function(Trees, na.rm=T) length(unique(Trees, > na.rm=T))) > > and alternately: > >>tapply(SppID, PlotID, function(Trees) length(unique(Trees)), na.rm=T) > > which doesn't seem to convince [r] to ignore the NAs. What am I doing > wrong? > > Thanks, > > Ian > > [[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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.