Re: [R] data manipulation help

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Tue 16 Aug 2005 - 17:31:54 EST

roberto munguia <munguiar <at> posgrado.ecologia.edu.mx> writes:

>
> I have a dataframe with 468 individuals (rows) that I captured at least once
> during 28 visits (columns), it looks like:
>
> mortality[1:10,]
>
>
> 1 1 0 0 0 1 1
> 1 0 0 0
..
> so I can know how many times every individual was captured, 0= not capture,
> 1=capture.
 

> I also want to know when was the first and the last capture for every
> individual,

This should give you a starter

# create play data
cap = data.frame(matrix(rbinom(120,1,0.3),nrow=10))

firstthat<-function(x) which(x)[1] # stolen from Thomas Lumley

# Make your data logical; not really needed, but easier to understand cap.log = cap==1
apply(cap.log,1,firstthat) # gives first captures

Dieter



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Aug 16 17:38:06 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:22:14 EST