Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subset of ESet /dividing ESet

Is it possible to subset a ExpressionSet like this:

SUB=ESet[,ESet@phenoData@data$x==c(0,1)]

in X are values from 0-9, and I just want the entries when x=0 or x=1.

like image 261
Azil Avatar asked Jan 31 '26 02:01

Azil


1 Answers

Try the following:

SUB=ESet[, ESet$x %in% c(0,1)]

At first glance, the difference between == and %in% seems only subtle.

x <- 0:9

x[x==c(0, 1)]
[1] 0 1

> x[x %in% c(0, 1)]
[1] 0 1

But %in% will never return NA, and this could be useful, or even essential, depending on what you want to do. In the following constructed example, == returns NA, whilst %in% returns the expected result:

x <- c(NA, 0:9)

x[x==c(0, 1)]
[1] NA

x[x %in% c(0, 1)]
[1] 0 1

But the difference is much deeper than this. From the help files for ?== it is apparent that when making binary comparisons between vectors of unequal length, the elements of shorter vectors are recycled as necessary.

Try for example the following:

x <- 0:9
x[x==c(1, 2)]
integer(0)

This results in an empty vector. If you recycle the vector c(1, 2), it quickly becomes apparent why:

x:       0 1 2 3 4 5 6 7 8 9
c(1, 2): 1 2 1 2 1 2 1 2 1 2
'==':    F F F F F F F F F F
like image 124
Andrie Avatar answered Feb 02 '26 16:02

Andrie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!