[R] Applying a function

Joanie Van De Walle joanie.van-de-walle.1 at ulaval.ca
Fri Dec 23 16:25:23 CET 2011


   Hi,

   I need help writing a function

   I capture seal pups mutliple times during the lactation season in order to
   monitor their growth rate. When I release them, the recovery (mother-pup)
   time is not the same for all individuals. I want to know if individuals that
   recover their mother the fastest are the ones with the highest growth rates.

   So, I noted at every release if the pup reovered his mother before we leave
   (yes or no). My dataframe looks like this

   Capture nb individual individual capture motherrecovery growth rate
   1          1          1                  n              0.5
   2          1          2                  y              0.5
   3          1          3                  y              0.5
   4          1          4                  y              0.5
   5          1          5                  n              0.5
   6          2          1                  y              0.3
   7          2          2                  y              0.3
   8          3          1                  y              0.4
   9          3          2                  n              0.4
   10         3          3                  y              0.4
   ...

   I want to calculate a rate of mother recovery by individual, i.e. nb of
   recoveries (y)/nb of captures. So for indivial 1 it would be 3/5 = 0.6. I
   want  to write a function that does this for all the individuals in my
   dataframe,  i.e. around 400 individuals (this is why I want to write a
   function, it would be too long by hand)

   Thank you,



   Joanie Van de Walle

   Étudiante à la Maîtrise en Biologie
   Département de Biologie
   1045, avenue de la Médecine Pavillon Vachon,
   bureau 2044 Université Laval
   Québec, Canada, G1V 0A6


More information about the R-help mailing list