[R] data manipulation help

From: <munguiar_at_posgrado.ecologia.edu.mx>
Date: Wed 17 Aug 2005 - 06:37:54 EST

Thanks to Patrick Burns, Dieter Menne and Peter Alspach for your help.

Peter Alspach indicated me how to get the first and the last capture of every individual with the following code:

capture <- matrix(rbinom(40, 1, 0.3), 4, 10)

capture

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

[1,] 0 0 0 0 0 1 1 0 1 1
[2,] 1 0 1 0 0 0 1 1 1 0
[3,] 0 0 0 0 0 0 1 0 1 0
[4,] 0 1 0 1 1 0 0 0 0 0

firstcap<-apply(capture, 1, function(x) min((1:length(x))[x==1])) [1] 6 1 7 2
lastcap<-apply(capture, 1, function(x) max((1:length(x))[x==1])) [1] 10 9 9 5

Roberto

Hello everybody,

 I have a dataframe with 468 individuals (rows) that I captured at least once during 28 visits (columns), iso I can know how many times every individual was captured, 0= not capture, 1=capture.

persistence<-apply(mortacap2,1,sum)

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

which(mortacap2[1,]==1)

X18.10.2004 X26.10.2004 X28.10.2004 X30.10.2004

          1 5 6 7 I can estimate manually row by row, but I dont get how to estimate the first and the last capture, to all individuals in the database at the same time.

I tried
d<-numeric(368)
for (i in 1:368) {d[i]<-which(mortacap2[1:368,]==1} but it didnt work. Any help would be appreciated.

Thanks in advance!!

Roberto Munguia Steyer
Departamento Biologia Evolutiva
Instituto de Ecologia, A.C.
Xalapa, Veracruz.
MEXICO  Windows XP
R 2.10



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 Wed Aug 17 06:47:52 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:24:51 EST