First, it may be a good idea to use 1 for âyesâ and 0 for ânoâ in the motherrecovery column.
Then if you name your table e.g tab1, you may try something like this.. sum(tab1[,2]==1*tab1[,4])/sum(tab1[,2]==1) 2011/12/23 Joanie Van De Walle <joanie.van-de-wall...@ulaval.ca> > > 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 > ______________________________________________ > 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. > [[alternative HTML version deleted]]
______________________________________________ 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.