[BioC] to extract just some columns of an exprsSet

Vincent Carey 525-2265 stvjc at channing.harvard.edu
Thu Sep 23 12:48:31 CEST 2004


> Dear all,
>
> I have a programming problem with R, but in connection with arrays:
> My goal is to extract just some columns (for which I have the label of
> each) of an object of exprsSet type: the resulting object of the expresso()
> command from the affy package.
>
> To be precise, let's say that I have 12 arrays, so my exprsSet object is a
> matrix of some thousands  of lines by 12 columns.
>
> My problem is that I don't have the rank of the columns I want to extract,
> but just the labels.
> Let's say I have a matrix of 12 colums labelled "sample1" to sample12". I
> want to extract the columns labelled "sample1", sample4" and sample6",
> which are non contiguous on my exprsSet matrix, in order to create a new
> matrix with these columns only.

the exprSet structure is designed to make such operations extremely
simple.  to illustrate, consider the example exprSet called eset
in Biobase

library(Biobase)
data(eset)
colnames(exprs(eset))

now you will see that the column names are the letters A-Z for
this example; in your case, they should be sample1-sample12 in some
arbitrary order

suppose I just want the columns "D", "H", "J":
eset2 <- eset[, c("D", "H", "J")]

eset2 is now the desired exprSet

[if for some reason your exprSet lacks column labels in the exprs
component, you can add them, but be sure to add the same labels
as the rownames(pData(yourEset))]



More information about the Bioconductor mailing list