[R] rarefy a matrix of counts

From: Brian Frappier <brian.frappier_at_gmail.com>
Date: Tue 10 Oct 2006 - 21:40:47 GMT


Hi all,

I have a matrix of counts for objects (rows) by samples (columns). I aimed for about 500 counts in each sample (I have about 80 samples) and would now like to rarefy these down to 100 counts in each sample using simple random sampling without replacement. I plan on rarefying several times for each sample. I could do the tedious looping task of making a list of all objects (with its associated identifier) in each sample and then use the wonderful "sampling" package to select a sub-sample of 100 for each sample and thereby get a logical vector of inclusions. I would then regroup the resulting logical vector into a vector of counts by object, rinse and repeat several times for each sample.

Alternately, using the same list, I could create a random index of integers between 1 and the number of objects for a sample (without repeats) and then select those objects from the list. Again, rinse and repeat several time for each sample.

Is there a way to directly rarefy a matrix of counts without having to create a list of objects first? I am trying to switch to R from Matlab and am trying to pick up good programming habits from the start.

Much appreciation!

        [[alternative HTML version deleted]]



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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Oct 11 07:45:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 11 Oct 2006 - 06:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.