Subset by samples for an ExpressionSet object
-
28-04-2021 - |
Pregunta
I have an ExpressionSet object with 100 samples:
> length(sampleNames(eset1))
100
I also have a vector of the names of 75 samples (not the data itself):
> length(vecOf75)
75
How can I subset eset1
(and save it) according to the 75 sample names? That is, I want to disregard those samples in eset1
whose names are not listed in vecOf75
. Bear in mind that some of the samples corresponding to the 75 sample names may not be in eset1
. Thus,
> length(sampleNames(eset1))
should now give something <75.
Solución
An ExpressionSet can be subset like a matrix, so maybe
eset2 = eset1[, sampleNames(eset1) %in% vecOf75]
or if all(vecOf75 %in% sampleNames(eset1))
then just
eset1[, vecOf75]
Not sure what 'save' means; either save(eset2, "some_file.rda") or extracting the components exprs(eset2)
, pData(eset2)
etc., and using write.table
and other standard R functions.
Otros consejos
eset1 <- vecOf75[vecOf75 %in% eset1]
This says, save to eset1 those of vecOf75 where vecOf75 is in eset1
A trivial example using numbers:
eset1 <- sample(1:100)
vecOf75 <- sample(1:200,75)
eset1 <- vecOf75[vecOf75 %in% eset1]
Alternatively, you could use subset()
but, getting used to subsetting via ']' is much more useful programmatically.
subset(vecOf75, vecOf75 %in% eset1)