[BioC] how split a matrix

Martin Morgan mtmorgan at fhcrc.org
Fri Feb 24 15:16:17 CET 2012


On 02/24/2012 05:27 AM, Ali Mohammadian wrote:
> Hi Sirs,
>
> I have a matrix, and I have written  a function to split it by its
> columns, the algorithm works manually, but does not work in R:
>
> A= matrix (rnorm (96),8,12)
> get.replicates = function (A, reps=reps){
> 	temp = array(-999,dim=c(dim (A) [2]/reps,dim(A) [1],reps))
> 	for (replicates.no in 1: (dim (A) [2]/reps)) {
> 	temp [replicates.no, , ] = A [ , reps*(replicates.no-1)+1:
> reps*(replicates.no) ]

Maybe you mean

   reps * (replicates.no - 1) + seq_len(reps)

? (seq_len(reps) is safer than 1:reps, e.g., when reps=0). If so then

   dim(A) = c(nrow(A), reps, ncol(A) / reps)

creates an array; if the first index of the updated A must be the 
replicate, then follow this with aperm(A, c(3, 1, 2)).

Martin

> 	}
> temp	
> }
>
> get.replicates (A,3)
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



More information about the Bioconductor mailing list