[BioC] Data types. How to convert a matrix, vector into a list

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Thu Aug 19 22:28:33 CEST 2004


On Thu, 2004-08-19 at 17:41, S Peri wrote:
> Dear group, 
> Apologies for asking the most chomped FAQ.
> 
> I have a file with list of gene names(genes.txt):
> EGF
> EGFR
> PTPN6
> TIEG2
> MAPK1
> 
> 
> I have another object in R, I do not know the data
> type for that object that looks like this
> ("lidnames"):
> "RABGGTA"   "MAPK3"     "TIE" "CYP2C19" 
> 
> 
> > lidnames[1:10]
>  100_g_at   1000_at   1001_at 1002_f_at 1003_s_at    
> "RABGGTA"   "MAPK3"     "TIE" "CYP2C19"    "BLR1" 


lidnames[1:10] is supposed to have 10 elements, yet you only showed 5.
This is similar to the following confusing command.

> print(1:10)
[1] 1 2 3 4 5


> 
> I want to pick list of genes from lidnames object that
> are in genes.txt.  I am using %in% function.
> 
> >mygenes<-read.table("genes.txt")
> 
> > mygenes[mygenes %in% lidnames]
> NULL data frame with 164 rows
> > 

You probably want 

 mygenes[ rownames(mygenes) %in% names(lidnames) , ]

Also look at and run the examples in help("merge").

I would strongly suggest you learn some R basics to do with basic data
structures (vector, matrix, list) and how to subset them properly. It
appears that you are trying to learn R by trial and error. R is much
like any programming language in that it will only pickup syntax and
coding errors not intellectual errors.



> I am unable to pullout genes from lidnames object.
> 
> Is it because that lidnames is as a list type and
> mygenes object is as a vector/matrix type.
> 
> How can I convert mygenes to list type where I can
> have the elements:
> 
> "EGF","EGFR","PTPN6","TIEG2","MAPK1".
> 
> I think in this way I can pull out the names from
> lidnames object or any other complex matrix. 
> 
> Please help me. 
> 
> Thank you
> SP
> 
> 
> 
> 		
> _______________________________
> 
> Win 1 of 4,000 free domain names from Yahoo! Enter now.
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
>



More information about the Bioconductor mailing list