use 'match' to convert the names to column indices and then use that for
indexing
indx <- match(subCols, names(yourMatrix)
mySubset <- yourMatrix[, indx]
Sent from my iPad
On Jul 5, 2013, at 2:22, Chirag Gupta <cxg040 at email.uark.edu> wrote:
> Hi All
>
> I have a huge matrix m (10276 X 10276) dimension with same column name and
> row names. (its a gene correlation matrix). I have another text file which
> has 2700 names, basically locus ID of genes, which are also
> rownames/colnames in m. Now I want to select all those columns from m whose
> names match with the names in the text file and return ONLY those columns
> and ALL the rows in a matrix format.
> That is, the output should a matrix of dimension 10276 X 2700.
>
> I have played around with subset and also tried all different methods like
> reading the text file, converting to matrix and character and DF and tried
> all possible ways I found on the web. The problem is that some of them work
> on a smaller simulated dataset but says "Subscript out of bounds"
when I
> try on the bigger matrix(m).
>
> Please help.. :(
>
> Thanks!
>
>
>
> --
> *Chirag Gupta*
> Department of Crop, Soil, and Environmental Sciences,
> 115 Plant Sciences Building, Fayetteville, Arkansas 72701
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.