how split a matrix
2
0
Entering edit mode
@ali-mohammadian-5008
Last seen 9.7 years ago
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) ] } temp } get.replicates (A,3)
• 822 views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 7 days ago
United States
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
ADD COMMENT
0
Entering edit mode
Yuan Hao ▴ 240
@yuan-hao-3658
Last seen 9.6 years ago
United States
There's a function 'split()' in R Just set the columns you would like to cluster into as a factor. > ?split() Usage: split(x, f, drop = FALSE, ...) split(x, f, drop = FALSE, ...) <- value unsplit(value, f, drop = FALSE) Cheers, Yuan On 24 Feb 2012, at 13:27, 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) ] > } > 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
ADD COMMENT

Login before adding your answer.

Traffic: 501 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6