[R] rarefy a matrix of counts

Petr Pikal petr.pikal at precheza.cz
Wed Oct 11 07:57:49 CEST 2006


Hi

I am not experienced in Matlab and from your explanation I do not 
understand what exactly do you want. It seems that you want randomly 
choose a sample of 100 rows from your martix, what can be achived by 
sample.

DF<-data.frame(rnorm(100), 1:100, 101:200, 201:300)
DF[sample(1:100, 10),]

If you want to do this several times, you need to save your result 
and than it depends on what you want to do next. One suitable form is 
list of matrices the other is array and you can use for loop for 
completing it.

HTH
Petr


On 10 Oct 2006 at 17:40, Brian Frappier wrote:

Date sent:      	Tue, 10 Oct 2006 17:40:47 -0400
From:           	"Brian Frappier" <brian.frappier at gmail.com>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] rarefy a matrix of counts

> 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 at 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.

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list