[R] subsetting a matrix with specified no of columns
Hello! All, I am working on 1x1000 matrix say 'mat' and i want to subset this matrix in a fashion that in new matrix i get columns 2,3,9,10,16,17,23,24...so on. That is pair of columns after every interval of 7. I tried following but i got an error which is obvious. >dim(mat) [1] 1 10 >a=mat[,c(seq(c(2,3),ncol(mat),7))] Warning messages: 1: In if (n < 0L) stop("wrong sign in 'by' argument") : the condition has length > 1 and only the first element will be used 2: In if (n > .Machine$integer.max) stop("'by' argument is much too small") : the condition has length > 1 and only the first element will be used 3: In if (dd < 100 * .Machine$double.eps) return(from) : the condition has length > 1 and only the first element will be used 4: In 0L:n : numerical expression has 2 elements: only the first used Is there any other way to do it?? Please, help! regards Lee [[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.
[R] bootstrapping a matrix and calculating Pearson's correlation coefficient
Hi All, I have got matrix 'data' of dimension 22000x600. I want to make 50 independent samples of dimension 22000x300 from the original matrix 'data'. And then want to calculate pearsons CC for each of the obtained 50 matrices. It seems it is possible to do this using 'boot' function from library boot but I am not able to figure out how? I am really stuck. Please help! Best Lee [[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.
[R] selective subsetting of a correlation matrix
Dear All, I have a correlation matrix say 'M' (4000x4000) for 4000 genes and I want to subset it to 'N' (190x190) for 190 genes. The list of those 190 genes are in variable 't'. So the idea is to read the names of genes from variable 't' and subset the matrix M accordingly. Any thoughts are welcome! Best Lee [[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.
[R] extracting values from correlation matrix
Hi! All, I have 2 correlation matrices of 4000x4000 both with same row names and column names say cor1 and cor2. I have extracted some information from 1st matrix cor1 which is something like this: rowname colname cor1_value a b0.8 b a0.8 c f 0.62 d k0.59 - - -- - - -- Now I wish to extract values from matrix cor2 for the same rowname and colname as above so that it looks similar to something like this with values in cor2_value: rowname colname cor1_value cor2_value a b0.8 --- b a0.8 --- c f 0.62 --- d k0.59 --- - - -- --- - - -- --- I am running out of ideas. So I decided to post this on mailing list. Please Help! Best Lee [[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.
Re: [R] column names of a correlation matrix
Thanks! guys for the help. cheers! Lee On Wed, Oct 28, 2009 at 7:03 PM, Tony Plate wrote: > Here's a simple example that might help you get what you want: > > set.seed(1) >> x <- matrix(rnorm(30), ncol=3, dimnames=list(NULL, letters[1:3])) >> (xc <- cor(x)) >> > a b c > a 1.000 -0.3767034 -0.7158385 > b -0.3767034 1.000 0.6040273 > c -0.7158385 0.6040273 1.000 > >> (cd <- data.frame(elt=outer(colnames(xc), colnames(xc), paste, >> sep=":")[upper.tri(xc)], row=row(xc)[upper.tri(xc)], >> col=col(xc)[upper.tri(xc)], cor=xc[upper.tri(xc)])) >> > elt row colcor > 1 a:b 1 2 -0.3767034 > 2 a:c 1 3 -0.7158385 > 3 b:c 2 3 0.6040273 > >> cd[order(-cd$cor),] >> > elt row colcor > 3 b:c 2 3 0.6040273 > 1 a:b 1 2 -0.3767034 > 2 a:c 1 3 -0.7158385 > >> >> > If you need something more efficient, try using which(..., arr.ind) to pick > out matrix style indices, e.g.: > >> (ii <- which(xc > -0.4 & upper.tri(xc), arr.ind=T)) >> > row col > a 1 2 > b 2 3 > >> cbind(ii, cor=xc[ii]) >> > row colcor > a 1 2 -0.3767034 > b 2 3 0.6040273 > >> >> > -- Tony Plate > > Lee William wrote: > >> Hi! All, >> I am working on a correlation matrix of 4217x4217 named 'cor_expN'. I wish >> to obtain pairs with highest correlation values. So, I did this >> >>> b=matrix(data=NA,nrow=4217,ncol=1) >>> rownames(b)=rownames(cor_expN) >>> for(i in 1:4217){b[i,]=max(cor_expN[i,])} >>> head(b) >>> >> [,1] >> aaeA_b3241_14 0.7181912 >> aaeB_b3240_15 0.7513084 >> aaeR_b3243_15 0.7681684 >> aaeX_b3242_12 0.5230587 >> aas_b2836_14 0.6615927 >> aat_b0885_140.6344144 >> >> Now I want the corresponding columns for the above values. For that I >> tried >> this >> >>> c=matrix(data=NA,nrow=4217,ncol=1) >>> for(i in 1:4217){b[i,]=colnames(max(cor_expN[i,]))} >>> >> >> And got the following error: >> Error in b[i, ] = colnames(max(cor_expN[i, ])) : number of items to >> replace >> is not a multiple of replacement length >> Any thoughts? >> >> Lee >> >>[[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. >> >> > [[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.
[R] column names of a correlation matrix
Hi! All, I am working on a correlation matrix of 4217x4217 named 'cor_expN'. I wish to obtain pairs with highest correlation values. So, I did this > b=matrix(data=NA,nrow=4217,ncol=1) > rownames(b)=rownames(cor_expN) > for(i in 1:4217){b[i,]=max(cor_expN[i,])} > head(b) [,1] aaeA_b3241_14 0.7181912 aaeB_b3240_15 0.7513084 aaeR_b3243_15 0.7681684 aaeX_b3242_12 0.5230587 aas_b2836_14 0.6615927 aat_b0885_140.6344144 Now I want the corresponding columns for the above values. For that I tried this > c=matrix(data=NA,nrow=4217,ncol=1) > for(i in 1:4217){b[i,]=colnames(max(cor_expN[i,]))} And got the following error: Error in b[i, ] = colnames(max(cor_expN[i, ])) : number of items to replace is not a multiple of replacement length Any thoughts? Lee [[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.