On Mon, Feb 9, 2009 at 8:03 AM, clion <birte_2@hotmail.com> wrote:

>
> this is good, but it doesn't solve my main problem (which I unfortunately
> din't post - very sorry )
> I would like to filter may data , for example by:
>
> dat.sub<-dat[dat$age>10 & dat$NoCaps>2,]
>
> So I need a column where the number of Captures is repeated for all rows of
> each captured animal.
> (or is there a better way to get a subset?)


Well, you could use merge:

   dat <- data.frame( id=c(1,1,1,2,2,2,3), age=c(2,3,4,2,3,5,3),
mass=c(1,2,3,2,3,4,3) )
   caps <- tapply(an$id,an$id,length)

   merge(dat,caps,by.x=1,by.y=0)

  id age mass y
1  1   2    1 3
2  1   3    2 3
3  1   4    3 3
4  2   2    2 3
5  2   3    3 3
6  2   5    4 3
7  3   3    3 1

	[[alternative HTML version deleted]]


