Your problem is a fairly common one and it has to do with how factors are
stored internally in R. They look like "geneA","geneB", etc to you, but to R
(for many things) they are kept as integers 1,2,3.

It should suffice to set

x <- as.character(tp[1,])

which forces x to be the string "geneA" and you can then put that into
gexp_1[,x]

More generally, you can probably do something like

gexp_1[,as.character(tp)]

to just get the columns of interest directly.

Hope this helps,

Michael Weylandt

On Wed, Sep 21, 2011 at 4:00 PM, Ahmed, Rizwan
<rizwan.ahmed@csc.mrc.ac.uk>wrote:

> Hi,
>
> I have a dataframe "gexp_1" with 115 rows of samples and 27000 columns of
> gene expression measurements with each column corresponding to one gene. I
> now have a smaller vector of genes "tp" for which I need to pull out the
> data form the data frame.
>
> #  first gene from the list with 16 genes
>
> x <- tp[1,]
> x
> [1] geneA
> 16 Levels: geneA, geneB...
>
> #unsuccessful
> gexp_1$x
> NULL
>
> #or
> gexp_1$x[1]
> NULL
>
> #but this works
> gexp_1$geneA
>
> I am sure that this is a fundamental error on my part since I am new to R,
> I would appreciate any advice. I am trying to construct a for loop to
> analyze data for sets of genes at a time but stuck at this step.
>
> Regards
> Rizwan
> ______________________________________________
> 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]]

