[R] Remove single entries

Chuck Cleland ccleland at optonline.net
Mon Sep 28 18:19:23 CEST 2009


On 9/28/2009 12:03 PM, Raymond Danner wrote:
> Dear Community,
> 
> I have a data set with two columns, bird number and mass.  Individual birds
> were captured 1-13 times and weighed each time.  I would like to remove
> those individuals that were captured only once, so that I can assess mass
> variability per bird.  I¹ve tried many approaches with no success.  Can
> anyone recommend a way to remove individuals that were captured only once?
> 
> Thanks,
> Ray

  How about something like this?

DF <- data.frame(BIRD = rep(1:10, c(1,1,2,10,5,6,7,1,8,9)),
                 MASS = rnorm(50,50,10))

DF$NOBS <- with(DF, ave(MASS, BIRD, FUN=length))

subset(DF, NOBS > 1)

> 	[[alternative HTML version deleted]]
> 
> ------------------------------------------------------------------------
> ______________________________________________
> R-help at 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list