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?)

thanks.



Dimitris Rizopoulos-4 wrote:
> 
> in this case you can use ave(), e.g., say 'dat' is the name of your data 
> frame, then try this:
> 
> dat$NoCaps <- ave(dat$Id, dat$Id, FUN = length)
> dat
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> clion wrote:
>> Hi there.
>> I collectad data of several animals (Id) that were caught and measured at
>> several occasions.
>> The dataframe looks like this:
>> Grouped Data: mass ~ age | Id
>> Id      age       mass
>> 1        1           5.4
>> 1        3           6.2
>> 1       15         10.0
>> 2        3           8.1
>> 2       10         12.8
>> 3        2           5.9
>> 3       10          7.1
>> 3       15         15.4
>> 3       17         16.2
>> 
>> Now, I would like to add a column that shows the number of captures per
>> Animal (so it'll look like this:) 
>> Id  ....   NoCaps
>> 1   ....     3
>> 1   ....     3
>> 1   ....     3
>> 2   ....     2
>> 2   ....     2
>> 3   ....     4  
>> 3   ....     4
>> ....
>>  
>> I understand that with 
>> tapply(Id,Id, length)
>> I can find out how many times each animal was caught, but how do I get
>> this
>> information into an extra column? I'm sure, this is an easy question, but
>> I'm lost, where to find the answer, or especially where to look it up. if
>> this is not a new question, please give me the key words to look for
>> it...
>> 
>> thanks in advance
>> 
>> 
>> 
>> 
>> 
>> 
> 
> -- 
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> 
> ______________________________________________
> 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.
> 
> 
:wistle::wistle::rules::rules::rules:
-- 
View this message in context: 
http://www.nabble.com/length-of-object-in-repeated-measures-tp21911978p21912355.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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